Installation dependencies
cd /var/www/html/laravel-project npm i -D laravel-mix@^5.x laravel-mix-template-minifier watch shelljs
Compression processing
Open File webpack.mix.js, and add the following content:
mix.minTemplate \= require("laravel-mix-template-minifier"); mix.minTemplate("storage/framework/views/\*.php", "storage/framework/views/", { collapseInlineTagWhitespace: true, collapseWhitespace: true, minifyCSS: true, minifyJS: true, processConditionalComments: true, removeAttributeQuotes: false, removeComments: true, removeTagWhitespace: false, trimCustomFragments: false, });
Compression parameters, see html-minifier (https://github.com/kangax/html-minifier?spm= a2c6h.14275010.0.0.70f559611yXtvP)
Create a new file compress.js in the project root directory and write the following content:
let shell = require("shelljs"); let watch = require("watch"); let precessing = false; watch.watchTree("./storage/framework/views", function(f, curr, prev) { if (!precessing) { precessing = true; shell.exec("npm run prod"); setTimeout(() => { precessing = false; }, 5000); } });
Auto-start monitoring command at boot
After completing the above steps, execute node compress.js on the command line to automatically monitor the pressure loss Template file, you can open the web page and see that the content in