I have an existing Laravel app and for part of the app, I'm using Laravel Mix. I have 6 single file components with the CSS inside the Vue file. My largest Vue file is 41KB, but the rest are 10-17kb each.
I'm using Laravel Mix to bundle the js inside webpack.mix.js : mix .js('resources/assets/js/app.js', 'dist/js'). My development app size is 767kb and my production bundle size is 265kb. Im trying to reduce the production app size, since it's just handling my vue files (js/CSS) so I'm not sure why it's so large.
package.json:
{
"private": true,
"scripts": {
"dev": "NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18.0",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.0",
"laravel-mix": "^4.0.14",
"lodash": "^4.16.2",
"resolve-url-loader": "^2.3.1",
"sass": "^1.17.2",
"sass-loader": "^7.1.0",
"vue": "^2.6.10",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.29.6"
},
"dependencies": { }
}
Do you have any ideas? 260kb feels like a lot for this.
Related
So I get the following Error whenever I compile for production:
But this only happens when compiling for prod, if I run: npm run dev. My app just runs like normal. The project is a ver old and there are not many dependencies I can update. I don't even know where to start debugging,
Here's the package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development NODE_OPTIONS=--max-old-space-size=8096 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": {
"ajv": "^6.0.0",
"axios": "^0.21.4",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.21.2",
"browser-sync": "^2.26.14",
"browser-sync-webpack-plugin": "^2.2.2",
"cross-env": "^5.2.1",
"imagemin": "^5.0.0",
"jquery": "^3.5.1",
"laravel-mix": "^2.0",
"lodash": "^4.17.21",
"popper.js": "^1.16.1",
"vanillatoasts": "^1.4.0",
"vue": "^2.6.12",
"vue-template-compiler": "^2.6.12",
"vue2-transitions": "^0.3.0",
"vuex": "^3.6.2"
},
"dependencies": {
"#vue/composition-api": "^1.7.1",
"chart.js": "^2.9.4",
"chartjs-plugin-datalabels": "^1.0.0",
"clipboard-polyfill": "^3.0.1",
"modal-video": "^2.4.8",
"moment": "^2.27.0",
"natives": "^1.1.6",
"node-sass": "^5.0.0",
"randomcolor": "^0.6.2",
"signature_pad": "^3.0.0-beta.4",
"v-wave": "^1.2.8",
"vue-carousel": "^0.18.0",
"vue-chartjs": "^3.5.1",
"vue-disable-autocomplete": "0.0.4",
"vue-randomcolor": "^1.0.4",
"vue-recaptcha": "^2.0.3",
"vue-router": "^3.5.1",
"vue-search-select": "^2.9.5",
"vue-select": "^3.12.1",
"vue-slick-carousel": "^1.0.6",
"vuejs-datepicker": "^1.6.2"
}
}
Any help will be appreciated.
I am trying to install VueJS in Laravel 8. If I run npm run dev command I am getting below error.
My prayer_time.vue file is like below.
<template>
<div>Welcome</div>
</template>
<script>
export default {
mounted() {
console.log("Example component mounted");
}
};
</script>
My package.json file is like below.
{
"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": {
"#popperjs/core": "^2.10.2",
"axios": "^0.21",
"bootstrap": "^5.2",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.11",
"sass-loader": "^11.0.1",
"vue": "^2.6.12",
"vue-loader": "^16.8.3",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"vue": "^3.2.45"
}
}
How can I run VueJS in laravel ?
I have done everything in accordance with the docs.
I installed storybook, and then I changed the config file the way they say has to be done to make storybook work on Vite, which supports the element-plus library.
.storybook/main.js:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.#(js|jsx|ts|tsx)'],
addons: ['#storybook/addon-links', '#storybook/addon-essentials'],
core: {
builder: '#storybook/builder-vite', // 👈 The builder enabled here.
},
}
Package.json:
{
"name": "elementui-practice",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 4173",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"element-plus": "^2.2.17",
"node-sass": "^7.0.3",
"sass-loader": "^13.0.2",
"vue": "^3.2.38"
},
"devDependencies": {
"#babel/core": "^7.19.1",
"#storybook/addon-actions": "^6.5.12",
"#storybook/addon-essentials": "^6.5.12",
"#storybook/addon-interactions": "^6.5.12",
"#storybook/addon-links": "^6.5.12",
"#storybook/builder-vite": "^0.2.2",
"#storybook/testing-library": "^0.0.13",
"#storybook/vue3": "^6.5.12",
"#vitejs/plugin-vue": "^3.0.3",
"babel-loader": "^8.2.5",
"eslint": "^8.23.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-storybook": "^0.6.4",
"eslint-plugin-vue": "^9.5.1",
"sass": "^1.55.0",
"vite": "^3.0.9",
"vue-cli-plugin-storybook": "~2.1.0",
"vue-loader": "^16.8.3"
}
}
If I run only the element-plus (npm run dev), the library works.
If I run npm run storybook, element-plus styles are not applied to the components or elements. Normal css works, but element-plus components and styles do not work.
Add these code to storybook's preview.js
import { app } from '#storybook/vue3'; //I use Vue3
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
app.use(ElementPlus);
I am trying to deploy an vue app in AWS amplify.
Below is my build configuration-
version: 0.1
frontend:
phases:
preBuild:
commands:
- npm install
build:
commands:
- npm run production
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
My package.json in the vue app -
{
"name": "foobar",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "./bin/web.js",
"serve": "vue-cli-service serve --mode development",
"production": "vue-cli-service build --mode production",
"sandbox": "vue-cli-service build --mode sandbox",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.18.0",
"bignumber.js": "^8.0.1",
"bootstrap": "^4.3.1",
"connect-history-api-fallback": "^1.5.0",
"cors": "^2.8.5",
"currency-formatter": "^1.5.3",
"ethereum-blockies": "^0.1.1",
"ethereum-blockies-base64": "^1.0.2",
"express": "^4.16.4",
"from-now": "^1.0.2",
"jquery": "^3.3.1",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"popper.js": "^1.14.7",
"socket.io-client": "^2.3.0",
"vue": "^2.5.17",
"vue-axios": "^2.1.4",
"vue-multiselect": "^2.1.4",
"vue-router": "^3.0.1",
"vuejs-paginate": "^2.1.0",
"vuex": "^3.0.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^3.2.0",
"#vue/cli-plugin-eslint": "^3.2.0",
"#vue/cli-plugin-unit-mocha": "^3.2.0",
"#vue/cli-service": "^3.2.0",
"#vue/test-utils": "^1.0.0-beta.20",
"babel-eslint": "^10.0.1",
"chai": "^4.1.2",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0-0",
"node-sass": "^4.11.0",
"sass-loader": "^7.1.0",
"vue-cli-plugin-bootstrap": "^1.0.0-alpha.1",
"vue-template-compiler": "^2.5.17"
}
}
In the build step it's failing, so I pulled up the log and saw following error-
2020-03-25T06:37:48.522Z [WARNING]: sh: vue-cli-service: command not
found
Why the error? vue-cli-service is there in the dev dependencies.
A quick fix that did work for me is to install #vue/cli-service globally with this command npm install -g #vue/cli-service
Also make sure your npm install command runs in NODE_ENV=development otherwise devDependencies won't be installed.
You may want to use npm ci or to trash your node_modules, at least once just as a test. Seems like most CICD systems hitting this issue were resolved by destroying the node_modules artifact: https://github.com/vuejs/vue-cli/issues/2404
Is the vue-cli-service not intended only to be used for development? Amplify is not going to serve your content from that service, its a development dependency which you would use to run locally during development. I think you don't want a "start" script there at all as Amplify would look in your public folder and serve the index.html file there.
I'm running a Laravel project, and I have some vue files which I need to change (for example, erasing some stuff), but the thing is I erase them from the vue file, but they are still appearing on the website. If I modify anything else, like a welcome.blade or whatsoever, it does work, but not with this vue files.
Only time I got it to work was stopping the project, running npm run dev, npm run watch --poll and starting the server again with php artisan serve, but when I tried doing it again, it didn't work.
I don't know if I am missing something obvious here. Please help my out :) and also, if I'm missing some information here please tell me so I can post it so someone can help me. Thanks!
This is my package.json that is on my root folder.
{
"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.1.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.15.2",
"sass-loader": "^7.1.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.11"
}
}
Well your file need to be compile so you need to run when editing npm run watch and you'll see live changement on reload and possibly some error discarding on the terminal you are running it from.
This is explicitly specify in the "tips" of Laravel documentation about Vue.