I'm a beginner in Vuejs , i've make a project and now i want to deploy it ,
i've tried to run
npm run build
like in Ember js and other js front end frameworks normally it will create a dist folder that contain my source code but i could not do that because the build script is not defined in the Vuejs which came with Laravel .
and i also tried to compress the project and upload it to my server and run it like other normal Laravel project but always Vuejs code not working, is there a specific way to deploy it ?? i've tried to search but i didn't find the solution
Your available scripts can be seen in package.json in the main laravel app folder.
There you should see something like:
"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"
},
Use npm run production for production builds and npm run dev for development builds.
In your webpack.mix.js file in the main folder, you can define your webpack configuration and therefore deployment settings. Have a look at https://laravel.com/docs/6.x/mix for details.
If you leave the standard implementation, your resources/js/app.js will be compiled to public/js/app.js.
You can include the file in your Laravel Blade template like this:
<script src="{{ mix('js/app.js') }}"></script>.
Related
I have my notifications working locally, but once deployed to production, it's not showing anything in the console.
#pushonce('custom-scripts')
<script>
Echo.private('App.Models.User.' + #js($user->id)).notification((notification) => {
console.log(notification); <---nothing printed in console on production.
#this.call('addNotification', notification);
});
</script>
#endpushonce
If I open the console on production and type Echo it sees it, so I know Echo is imported or whatever.
My app is deployed on Laravel Forge. I've run the following commands on prod:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan optimize:clear
Nothing seems to have any impact.
Also, I'm aware that Livewire has listeners for Echo, but this is the only way I was able to get things working locally.
UPDATE
I use Github actions for my CI/CD pipeline, and within my actions I'm running the following scripts, which I thought would be enough, but perhaps not:
- uses: actions/checkout#main
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Install dependencies
run: npm install
- name: Compile assets
run: npm run production
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
I thought I would post my build scripts as I don't think I've ever really paid much attention to them, and I'm not sure if they're set up right. I also don't have an npm run build script, and don't know what I would put in it:
"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"
},
UPDATE:
I ran npm run prod and npm run production locally, which theoretically should produce the same bundle I'm seeing in production, and I got the same result locally, i.e. I'm seeing the notification logged to the console. So it doesn't appear to be related to my build script.
Also, Echo is making it into the production build because I can call it from the console in production. So there has to be some other reason why it's not working.
Echo is a JS lib and i suggest that you have to build your scripts before you deploy. If your build your javascript in your pipeline make sure that your pipeline run the npm build command.
Add this to your Laravel Forge deployment script:
npm ci
npm run build
I know that I need to run npm run build to build my assets so they are minified for the web. My problem is I'm missing the script in my package.json file and I don't know what the correct code is for this.
package.json:
"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"
},
After I run the command it should create the dist folder. This is what I need. I'm not sure why my project is missing that script.
You can check the Laravel Mix section of the documentation.
As it states:
Mix is a configuration layer on top of Webpack, so to run your Mix
tasks you only need to execute one of the NPM scripts that is included
with the default Laravel package.json file:
// Run all Mix tasks...
npm run dev
// Run all Mix tasks and minify output...
npm run production
This will generate your files in the public directory, by default:
/public/js/app.js
/public/css/app.css
Of course, you can customize this in the ./webpack.mix.js to do a bunch of other operations (like copying files, customizing the Webpack config, extracting vendors, etc) that you can see in the docs.
I'm using npm run watch watching assets for changes, and it works good except that it takes 10 seconds before it starts to listening for changes again after every compile.
So if I save a file it will successfully compile, but if I make changes and save again before 10 seconds passed nothing happens.
I expect the npm run watch to be ready directly after every compilation.
How can I debug this? I don't know if this is an issue with Laravel Mix or something else?
I'm using webpack and my VM has a Ubuntu system. My
This is from package.json:
"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"
},
webpack.mix.js
mix.js('resources/js/main.js', 'public/js/app.js')
.sass('resources/sass/app.scss', 'public/css')
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind-config.js') ],
});
I'm using webpack and heroku.
When I push my web to heroku it will restart and do "npm run start".
What I want to do is doing "npm run start" with "npm run build" when I push my web to heroku
here's my pakage.json
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --hot --open --inline",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
"start": "set NODE_ENV=production webpack --progress --hide-modules&&node server.js"
},
What I tried is this but, not working
"start": "set NODE_ENV=production webpack --progress --hide-modules&&node server.js"
Update:
Maybe your scripts isnt working in heroku because, by default they are running linux and you are triyng to run the "set" command that belongs to windows. Try removing it form the script and let cross-env do all the rest of the work for you :)
Previous response:
I know this isnt the best solution, but I hope it helps you:
If the problem is in the concatenation of commands to run, you can install "npm-run-all" to your project and then you will be able yo run several scripts in secuential order.
In your case, you could set the scripts like this:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --hot --open --inline",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
"start": "set NODE_ENV=production webpack --progress --hide-modules",
"run-server": "node server.js",
"build-sart-n-run": "run-s build start run-server"
}
After that you can run ,either via Heroku CLI using a procfile or using the tools that the web UI gives you when you login, the next command:
$ node build-sart-n-run
sorry if my english inst very good :)
Struggling with Laravel 5.4 vagrant box on Windows 10, trying to get laravel-mix to work. My end goal is to set up a ServiceWorker and asset caching for a PWA (Progressive Web App), and must admit node, npm, mix/gulp are puzzling me. From what I see in forum posts, it is rather fragile technology, susceptible to breaks with any minor change or variation on the environment.
I get this error message 4 times when running "npm run dev" (once for each compiled js resource):
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/home/vagrant"
at /home/vagrant/Code/laravel-basics/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
Here is my 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",
"development2": "./node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"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 --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.5",
"font-awesome": "^4.7.0",
"jquery": "^3.1.1",
"laravel-mix": "^1.4.2",
"lodash": "^4.17.4",
"node-sass": "^4.5.3",
"sw-precache-webpack-plugin": "^0.11.4",
"vue": "^2.1.10",
"webpack-rtl-plugin": "^1.5.0"
}
}
The latest attempt was running vagrant from an Administrator Command prompt before doing "rm -rf node_modules && npm install" (or its equivalent). I don't like this but the npm install went a lot smoother than with "--no-bin-links" options. I also tried yarn instead of npm install.
That should fix it. Don't forget to include a .babelrc with
{
"presets": ["es2015"]
}
I tried many things but it seems the combination of
Running Vagrant/Homestead as Administrator in command prompt
Installing es2015 globally, in addition to --no-bin-links
Restarting the VM so the global install with environment changes takes effect
THEN, npm run dev
did the trick. I tried this sequence on a new laravel project on the same machine. Hopefully it will also work when I destroy my VM and redo this...