How to configure webpack to compile Vuejs and Laravel in different folders - laravel

My problem: npm run watch (running in the backend side of the server) returns a blank html page, any updates that I make in the frontend are not compiled. The problem started to occur randomly, the only thing that changed is that I installed auth ui in Laravel.
My directory setup:
www
- frontend (Vuejs)
- standard vue files/folders
- package.json
- vue.config.js
- babel.config.js
- etc.
- backend (Laravel)
- standard laravel files/folders
- package.json
- webpack.mix.js
I know this is not an nginx problem but just in case you need to know, nginx rootfolder is pointing to /var/www/backend/public and is using a let's encrypt ssl certificate.
vue.config.js
module.exports = {
lintOnSave: false,
runtimeCompiler: true,
configureWebpack: {
resolve: {
symlinks: false
}
}
};
package.json (frontend)
{
"name": "a random name",
"author": "that will be me :)",
"description": "nice description",
"version": "1.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"clearCache": "jest --clearCache",
"release": "npm-run-all clearCache lint build test:unit test:e2e"
},
"dependencies": {
"axios": "^0.19.2",
"cesium": "^1.71.0",
"core-js": "3.5.0",
"html-webpack-plugin": "^4.3.0",
"html-webpack-template": "^6.2.0",
"nouislider": "14.1.0",
"requirejs": "^2.3.6",
"v-tooltip": "2.0.2",
"vue": "2.6.10",
"vue-carousel": "0.18.0",
"vue-clickaway": "2.2.2",
"vue-kinesis": "^1.1.5",
"vue-lazyload": "1.3.3",
"vue-material": "1.0.0-beta-11",
"vue-router": "3.1.3"
},
"devDependencies": {
"#vue/cli-plugin-babel": "4.1.1",
"#vue/cli-plugin-eslint": "4.1.1",
"#vue/cli-plugin-router": "4.1.1",
"#vue/cli-service": "4.1.1",
"#vue/eslint-config-prettier": "6.0.0",
"babel-eslint": "10.0.3",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "3.1.1",
"eslint-plugin-vue": "^6.2.2",
"gulp": "^4.0.2",
"gulp-append-prepend": "1.0.8",
"prettier": "1.19.1",
"sass": "1.23.7",
"sass-loader": "8.0.0",
"vue-template-compiler": "2.6.10",
"webpack": "^4.44.0",
"webpack-cli": "^3.3.12"
}
}
package.json (backend)
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "7.*",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"animo-core": "^1.0.8",
"bootstrap": "^4.5.0",
"gsap": "^3.4.2",
"jquery": "^3.5.1",
"paper": "^0.12.11",
"popper": "^1.0.1",
"popper.js": "^1.16.1",
"requirejs": "^2.3.6",
"simplex-noise": "^2.4.0",
"vue": "^2.6.11",
"vue-axios": "^2.1.5",
"vue-kinesis": "^1.1.5",
"vue-roller": "^1.12.1",
"vue-router": "^3.3.4",
"vue-text-transition": "^1.0.19",
"vuex": "^3.5.1"
}
}
webpack.mix.js
const path = require('path');
const mix = require('laravel-mix');
mix.webpackConfig({
resolve: {
alias: {
"#": path.resolve(__dirname, "resources/js/")
}
}
});
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps();
mix.copy('../frontend/public', 'public');
What I would like to happen (again)
Run npm run watch within the backend. Then it auto compiles my frontend to the public directory in the frontend. The backend then uses mix.copy to copy the compiled app.js and app.scss (or just all the content within the public folder) to the backend's public directory.
If you need any more information, please ask, I've been trying to fix this for the last couple of days now and I can't seem to find the solution anywhere.

Related

Error when compiling in production mode "is not a function" Vue Laravel Mix

I have a Laravel, VueJs, VueRouter, Vuex application using Webpack to compile my assets.
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.14.0",
"axios": "^0.18",
"bootstrap": "^4.0.0",
"laravel-mix": "^3.0.0",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"vue": "^2.5.7"
},
"dependencies": {
"#fullcalendar/core": "^5.11.3",
"#fullcalendar/daygrid": "^5.11.3",
"#fullcalendar/interaction": "^5.11.3",
"#fullcalendar/list": "^5.11.3",
"#fullcalendar/timegrid": "^5.11.3",
"#fullcalendar/vue": "^5.11.3",
"ajv": "^6.12.3",
"animate.css": "^3.7.2",
"aos": "^2.3.4",
"apexcharts": "^3.33.0",
"chart.js": "^2.7.3",
"element-ui": "^2.4.8",
"imagemin": "^6.0.0",
"jquery": "^3.4.1",
"moment": "^2.27.0",
"node-sass": "^4.14.1",
"numeral": "^2.0.6",
"simple-keyboard": "^2.29.72",
"toastr": "^2.1.4",
"vue-apexcharts": "^1.6.2",
"vue-chartjs": "^3.4.0",
"vue-data-tables": "^3.4.5",
"vue-router": "^3.5.2",
"vue-touch-keyboard": "^0.3.2",
"vuedraggable": "^2.24.3",
"vuex": "^3.5.1",
"xml-js": "^1.6.11"
}
}
when i build in production mode npm run prod i get the error s is not a function
but if i build in dev like npm run watch or npm run dev i don't get the error.
How can I debug where the error is in the code so I can fix it? It only shows me in the vue.common.prod line.
vue.common.prod.js:11 TypeError: s is not a function
at e (vue.common.prod.js:11:68600)
my file webpack.mix.js
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/front/app.js', 'public/js')
.extract(['vue','vuex', 'jquery', 'bootstrap', 'axios', 'element-ui', 'lodash', 'moment', 'popper.js'])
.version();
mix.webpackConfig({
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'#': path.join(__dirname, './resources/js'),
'~': path.join(__dirname, './resources/js/front'),
'##': path.join(__dirname, './modules'),
'#components': path.join(__dirname, './resources/js/components')
}
},
output: {
filename:'[name].js',
chunkFilename: 'js/[name].js',
},
}).sourceMaps()
option 01) :
check the function you wrote
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute s function that is not initialized or is not initialized correctly. This means that the expression did not return s function object. So you need to understand that what you are trying to achieve is not s feature.
option 02) :
remove node_module and clear cache npm cache clear --force.
after that reinstall node_module by using npm install.
option 03) :
check your imported thing forgot the curly braces in an import statement.

Blank page is showing laravel and vue

Info
Using laravel and vue project
After installing composer install and npm install blank page is showing
Laravel 8, Vue vue#3.2.31, PHP 8 and ubuntu 20
Project location /www/html/project
Start the project using php artisan serve
Network tab http://127.0.0.1:8000/ showing status 200 but in preview tab
Error
No warning and console error. Network tab http://127.0.0.1:8000/ showing status 200 but in the preview tab below error gives
There was a problem loading your site type details
Code
Webpack.mix.js
const plugins = [
require('postcss-import'),
require('tailwindcss'),
require('postcss-nested'),
require('autoprefixer')
];
mix
.webpackConfig({
resolve: {
alias: {
'#': __dirname + '/resources/js'
}
}
})
.js('resources/js/project/app.js', 'public/js').vue().version()
.js('resources/js/_default/admin.js', 'public/js').vue().version()
.postCss('resources/css/app.css', 'public/css', plugins)
.postCss('resources/css/admin.css', 'public/css', plugins)
.sass('resources/css/admin/bootstrap.custom.scss', 'public/css')
//.browserSync('127.0.0.1:8000')
//mix.dumpWebpackConfig();
if (mix.inProduction()) {
mix.version();
}
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"#vue/compiler-sfc": "^3.2.20",
"autoprefixer": "^10.4.0",
"axios": "^0.21",
"browser-sync": "^2.27.7",
"browser-sync-webpack-plugin": "^2.3.0",
"laravel-mix": "^6.0.0-beta.17",
"lodash": "^4.17.19",
"popper.js": "^1.16.1",
"postcss": "^8.3.11",
"postcss-import": "^12.0",
"postcss-nested": "^4.2",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.11",
"sass-loader": "^11.1.1",
"tailwindcss": "^2.2.19",
"vue": "^3.2.20",
"vue-loader": "^16.8.2",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"#headlessui/vue": "^1.4.1",
"#heroicons/vue": "^1.0.5",
"#tailwindcss/forms": "^0.3.4",
"bootstrap": "^4.6.1",
"formiojs": "^4.13.11",
"install": "^0.13.0",
"npm": "^8.1.1",
"or": "^0.2.0",
"vue-i18n": "^8.26.5",
"vue-router": "^4.0.12",
"webpack-shell-plugin-next": "^2.2.2"
}
}
I don't know what's wrong with this project, I tried deleting the node_modules and npm install but still got the same error, npm run hot also did not gives any error
const path = require('path');
mix.js(['resources/js/app.js','resources/js/_default/admin.js'], "public/js")
.vue()
.postCss(['resources/css/app.css', 'resources/css/admin.css'], "public/css", plugins)
.sass('resources/css/admin/bootstrap.custom.scss', 'public/css')
.webpackConfig({
resolve: {
alias: {
'#': path.resolve('resources/js'),
},
},
};);
if (mix.inProduction()) {
mix.version();
}

Laravel Mix / Tailwind compiling issue with css-loader

I am trying to compile my CSS using PostCSS in Laravel Mix - Laravel 8.50.0 (as stated in Install Tailwind CSS with Laravel), but when I compile my assets using: npm run watch I receive the following error.
ERROR in ./resources/css/app.css
(./node_modules/css-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use1!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use[2]!./resources/css/app.css)
Module build failed (from ./node_modules/css-loader/dist/cjs.js):
ValidationError: Invalid options object. CSS Loader has been
initialized using an options object that does not match the API
schema.
options.url should be one of these:
boolean | object { filter? }
-> Allows to enables/disables url()/image-set() functions handling.
-> Read more at https://github.com/webpack-contrib/css-loader#url
Details:
options.url should be a boolean.
options.url should be an object:
object { filter? }
at validate (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/webpack/node_modules/schema-utils/dist/validate.js:105:11)
at Object.getOptions (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/webpack/lib/NormalModule.js:527:19)
at Object.loader (/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/css-loader/dist/index.js:31:27)
Child mini-css-extract-plugin
/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/css-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use1!/Users/usser/Desktop/GIT/snitch/onesnitch.com/node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-6[0].rules[0].use[2]!/Users/usser/Desktop/GIT/snitch/onesnitch.com/resources/css/app.css
compiled with 1 error
webpack.mix.js
const mix = require("laravel-mix");
mix.webpackConfig({
stats: {
children: true,
},
})
.options({
terser: {
extractComments: false,
},
})
.js("resources/js/app.js", "public/js")
.vue({ version: 2 })
.postCss("resources/css/app.css", "public/css", [require("tailwindcss")])
.js("resources/frontend/js/app.js", "public/js/frontend")
.postCss("resources/frontend/css/app.css", "public/css/frontend", [
require("tailwindcss"),
])
.version();
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"autoprefixer": "^10.2.5",
"axios": "^0.21.1",
"css-loader": "^6.1.0",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.3.5",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "^10.1.1",
"tailwindcss": "^2.1.1",
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"#tailwindcss/aspect-ratio": "^0.2.0",
"#tailwindcss/forms": "^0.3.2",
"#tailwindcss/typography": "^0.4.0",
"alpinejs": "^2.8.2",
"aos": "^3.0.0-beta.6",
"dayjs": "^1.10.4",
"dotenv": "^8.2.0",
"secure-ls": "^1.2.6",
"vee-validate": "^3.4.5",
"vue": "^2.6.12",
"vue-i18n": "^8.24.1",
"vue-router": "^3.5.1",
"vuex": "^3.6.2",
"vuex-persistedstate": "^3.2.0",
"zxcvbn": "^4.4.2"
}
}
Thoughts would be greatly appreciated.
As a workaround, downgrade your css-loader package to a 5.x version.
npm install css-loader#5.2.7 --save-dev

NPM build failing with Webpack 5

About a day or 2 ago, I ran my NPM build, but it suddenly gave the error that the polyfill is not provided by default anymore with Webpack 5. I was able to fix a lot of the errors, but it keeps failing.
I get the following errors:
These are just a few of them.
I'm using laravel-mix#6.0.13 in this build with the following webpack.mix.js file:
const mix = require('laravel-mix');
require('mix-tailwindcss');
mix.webpackConfig({
resolve: {
fallback: {
fs: require.resolve('browserify-fs'),
path: require.resolve("path-browserify"),
"crypto": require.resolve("crypto-browserify"),
"https": require.resolve("https-browserify"),
"http": require.resolve("stream-http"),
"vm": require.resolve("vm-browserify"),
"os": require.resolve("os-browserify/browser"),
"stream": require.resolve("stream-browserify"),
"constants": require.resolve("constants-browserify"),
}
}
})
mix.options({ legacyNodePolyfills: false });
mix.js('resources/js/app.js', 'public/js').vue()
.sass('resources/scss/app.scss', 'public/css')
.tailwind('./tailwind.config.js')
mix.sass('resources/scss/admin.scss', 'public/css')
My packages.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"browserify-fs": "^1.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^6.0.13",
"lodash": "^4.17.4",
"mix-tailwindcss": "^1.3.0",
"popper.js": "^1.12",
"postcss": "^8.1",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.12",
"sass-loader": "10.*",
"tailwindcss": "^2.1.2",
"vue": "^2.5.7",
"vue-loader": "^15.9.5",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"buefy": "^0.9.6",
"jquery": "^3.6.0",
"mix-tailwindcss": "^1.3.0",
"query-string": "^7.0.0",
"slick-carousel": "^1.8.1",
"vue": "^2.6.12",
"vue-it-bigger": "^0.2.2"
}
}
Does someone know how to fix this?
Solved it!
I added the the NodePolyfillPlugin plugin to my webpack config. I added browserify-fs to resolve.fallback.fs like this.
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
mix.webpackConfig({
plugins: [
new NodePolyfillPlugin(),
],
resolve: {
fallback: {
fs: require.resolve('browserify-fs'),
}
}
})
After this the build kept failing, i finally figured out that for some reason i had import {vue} from 'laravel-mix' in my app.js . this was giving als the errors. After removing this it ran succesfully!

Module not found: Error: Can't resolve 'flag-icon-css' in

I am going to install this admin panel https://coreui.io/ (free version) in my laravel project. It contains a package.json file with the following dependencies:
"dependencies": {
"#coreui/coreui": "^2.1.5",
"#coreui/coreui-plugin-chartjs-custom-tooltips": "1.2.0",
"#coreui/icons": "0.3.0",
"bootstrap": "^4.2.1",
"chart.js": "2.7.3",
"core-js": "^2.6.1",
"flag-icon-css": "^3.2.1",
"font-awesome": "4.7.0",
"jquery": "3.3.1",
"pace-progress": "1.0.2",
"perfect-scrollbar": "^1.4.0",
"popper.js": "^1.14.6",
"simple-line-icons": "2.4.1"
},
So I am just going to put these dependencies in my package.json and run
npm install and npm run dev. My project's packaje.json is
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"dependencies": {
"#coreui/coreui": "^2.1.6",
"#coreui/coreui-plugin-chartjs-custom-tooltips": "1.2.0",
"#coreui/icons": "0.3.0",
"bootstrap": "^4.2.1",
"chart.js": "2.7.3",
"core-js": "^2.6.1",
"flag-icon-css": "^3.2.1",
"font-awesome": "^4.7.0",
"jquery": "3.3.1",
"node-sass": "^4.11.0",
"pace": "*",
"pace-progress": "1.0.2",
"perfect-scrollbar": "^1.4.0",
"popper.js": "^1.14.6",
"simple-line-icons": "^2.4.1"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"css-loader": "^2.1.0",
"jquery": "^3.2",
"laravel-mix": "^4.0.7",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.2",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.3"
}
}
But as result I see the following:
So, how I can fix it? What is wrong?
First of all ensure you have installed all packages successfully. I personally recommend you delete your node_modules then run npm install.
I think the problem is that your project doesn't found it's CSS/SASS dependencies.
Ensure to import all CSS/SASS files into your app.scss file.
For example for Simple Line Icons package you should do something like this.
#import "~simple-line-icons/scss/simple-line-icons";
Also double check all js. components
For example in your app.js
import 'coreui';

Resources