繁体   English   中英

Webpack.config.js 文件缩小 js 和 css。 - 使用 webpack 时如何缩小 js 和 css 文件?

[英]Webpack.config.js file minify js and css. - How to minify js and css files when using webpack?

我刚开始学习webpack,我不知道如何缩小所有文件(js和css)。 我知道如何使用 gulp,但是 webpack... 所以,我的配置文件如下所示:

var Encore = require('@symfony/webpack-encore');

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build')

    .addEntry('app', './assets/js/app.js')
module.exports = Encore.getWebpackConfig();

我真的不知道如何缩小,我已经阅读了很多信息,但我没有得到我想要的。

您可以使用 TerserPlugin

Encore.configureTerserPlugin((options) => {
   options.cache = true;
   options.parallel = true;
   options.terserOptions = {
   output: {
    comments: false,
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM