配置文件
configureWebpack: { plugins: [assetsPluginInstance], optimization: { minimize: true, minimizer: [ new TerserPlugin({ sourceMap:true, terserOptions: { ecma: undefined, warnings: false, parse: {}, compress: { drop_console: true, drop_debugger: true, pure_funcs: ['console.log'], // 移除console } } }) ] }
使用 npx vue-cli-service inspect --mode buildProd >> webpack.config.production1.js
打印了最终的webpack 配置信息如下
{ mode: 'development', context: '{ mode: 'development', context: '', devtool: 'cheap-module-eval-source-map', externals: { vue: 'Vue', 'vue-router': 'VueRouter', vuex: 'Vuex', axios: 'axios', 'element-ui': 'ELEMENT' }, node: { setImmediate: false, dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', child_process: 'empty' }, output: { path: '\\dist', filename: '[name].2_2_1.[hash].1590031014285.js', publicPath: '', globalObject: '(typeof self !== \'undefined\' ? self : this)', chunkFilename: '[name].2_2_1.[hash].1590031014285.js' }, resolve: { alias: { '@': '\\src', vue$: 'vue/dist/vue.runtime.esm.js' }, extensions: [ '.mjs', '.js', '.jsx', '.vue', '.json', '.wasm' ], modules: [ 'node_modules', '\\node_modules', '\\node_modules\\@vue\\cli-service\\node_modules' ] }, resolveLoader: { modules: [ '\\node_modules\\@vue\\cli-plugin-eslint\\node_modules', '\\node_modules\\@vue\\cli-plugin-babel\\node_modules', 'node_modules', '\\node_modules', '\\node_modules\\@vue\\cli-service\\node_modules' ] }, module: { noParse: /^(vue|vue-router|vuex|vuex-router-sync)$/, rules: [ /* config.module.rule('vue') */ { test: /\.vue$/, use: [ { loader: 'cache-loader', options: { cacheDirectory: '\\node_modules\\.cache\\vue-loader', cacheIdentifier: '5588e529' } }, { loader: 'vue-loader', options: { compilerOptions: { preserveWhitespace: false }, cacheDirectory: '\\node_modules\\.cache\\vue-loader', cacheIdentifier: '5588e529' } } ] }, /* config.module.rule('images') */ { test: /\.(png|jpe?g|gif|webp)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'img/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('svg') */ { test: /\.(svg)(\?.*)?$/, use: [ { loader: 'file-loader', options: { name: 'img/[name].[hash:8].[ext]' } } ] }, /* config.module.rule('media') */ { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'media/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('fonts') */ { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'fonts/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('pug') */ { test: /\.pug$/, oneOf: [ /* config.module.rule('pug').oneOf('pug-vue') */ { resourceQuery: /vue/, use: [ { loader: 'pug-plain-loader' } ] }, /* config.module.rule('pug').oneOf('pug-template') */ { use: [ { loader: 'raw-loader' }, { loader: 'pug-plain-loader' } ] } ] }, /* config.module.rule('css') */ { test: /\.css$/, oneOf: [ /* config.module.rule('css').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('postcss') */ { test: /\.p(ost)?css$/, oneOf: [ /* config.module.rule('postcss').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('scss') */ { test: /\.scss$/, oneOf: [ /* config.module.rule('scss').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('sass') */ { test: /\.sass$/, oneOf: [ /* config.module.rule('sass').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] } ] }, /* config.module.rule('less') */ { test: /\.less$/, oneOf: [ /* config.module.rule('less').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('stylus') */ { test: /\.styl(us)?$/, oneOf: [ /* config.module.rule('stylus').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] } ] }, /* config.module.rule('js') */ { test: /\.m?jsx?$/, exclude: [ function () { /* omitted long function */ } ], use: [ { loader: 'cache-loader', options: { cacheDirectory: '\\node_modules\\.cache\\babel-loader', cacheIdentifier: '23601776' } }, { loader: 'babel-loader' } ] }, /* config.module.rule('eslint') */ { enforce: 'pre', test: /\.(vue|(j|t)sx?)$/, exclude: [ /node_modules/, '\\node_modules\\@vue\\cli-service\\lib' ], use: [ { loader: 'eslint-loader', options: { extensions: [ '.js', '.jsx', '.vue' ], cache: true, cacheIdentifier: '413b12a3', emitWarning: true, emitError: false, eslintPath: '\\node_modules\\eslint', formatter: function () { /* omitted long function */ } } } ] } ] }, plugins: [ /* config.plugin('vue-loader') */ new VueLoaderPlugin(), /* config.plugin('define') */ new DefinePlugin( { 'process.env': { NODE_ENV: '"buildProd"', BASE_URL: '""' } } ), /* config.plugin('case-sensitive-paths') */ new CaseSensitivePathsPlugin(), /* config.plugin('friendly-errors') */ new FriendlyErrorsWebpackPlugin( { additionalTransformers: [ function () { /* omitted long function */ } ], additionalFormatters: [ function () { /* omitted long function */ } ] } ), /* config.plugin('hmr') */ new HotModuleReplacementPlugin(), /* config.plugin('progress') */ new ProgressPlugin(), /* config.plugin('html') */ new HtmlWebpackPlugin( { templateParameters: function () { /* omitted long function */ }, template: '\\public\\index.html' } ), /* config.plugin('preload') */ new PreloadPlugin( { rel: 'preload', include: 'initial', fileBlacklist: [ /\.map$/, /hot-update\.js$/ ] } ), /* config.plugin('prefetch') */ new PreloadPlugin( { rel: 'prefetch', include: 'asyncChunks' } ), /* config.plugin('copy') */ new CopyWebpackPlugin( [ { from: '\\public', to: '\\dist', toType: 'dir', ignore: [ '.DS_Store', { glob: 'index.html', matchBase: false } ] } ] ), { options: { filename: 'webpack-assets.json', prettyPrint: false, update: false, fullPath: true, manifestFirst: true, useCompilerPath: false, fileTypes: [ 'js', 'css' ], includeAllFileTypes: true, keepInMemory: false, integrity: false, metadata: { version: '2_2_1' }, processOutput: function (assets) { return JSON.stringify(assets, null, options.prettyPrint ? 2 : null); } }, writer: function () { /* omitted long function */ } } ], entry: { app: [ './src/main.js', 'babel-polyfill', 'classlist-polyfill' ] }, optimization: { minimize: true, minimizer: [ { options: { test: /\.m?js(\?.*)?$/i, warningsFilter: () => true, extractComments: true, sourceMap: true, cache: true, cacheKeys: defaultCacheKeys => defaultCacheKeys, parallel: true, include: undefined, exclude: undefined, minify: undefined, terserOptions: { ecma: undefined, warnings: false, parse: {}, compress: { drop_console: true, drop_debugger: true, pure_funcs: [ 'console.log' ] } } } } ] } } ', devtool: 'cheap-module-eval-source-map', externals: { vue: 'Vue', 'vue-router': 'VueRouter', vuex: 'Vuex', axios: 'axios', 'element-ui': 'ELEMENT' }, node: { setImmediate: false, dgram: 'empty', fs: 'empty', net: 'empty', tls: 'empty', child_process: 'empty' }, output: { path: '\\dist', filename: '[name].2_2_1.[hash].1590031014285.js', publicPath: '', globalObject: '(typeof self !== \'undefined\' ? self : this)', chunkFilename: '[name].2_2_1.[hash].1590031014285.js' }, resolve: { alias: { '@': '\\src', vue$: 'vue/dist/vue.runtime.esm.js' }, extensions: [ '.mjs', '.js', '.jsx', '.vue', '.json', '.wasm' ], modules: [ 'node_modules', '\\node_modules', '\\node_modules\\@vue\\cli-service\\node_modules' ] }, resolveLoader: { modules: [ '\\node_modules\\@vue\\cli-plugin-eslint\\node_modules', '\\node_modules\\@vue\\cli-plugin-babel\\node_modules', 'node_modules', '\\node_modules', '\\node_modules\\@vue\\cli-service\\node_modules' ] }, module: { noParse: /^(vue|vue-router|vuex|vuex-router-sync)$/, rules: [ /* config.module.rule('vue') */ { test: /\.vue$/, use: [ { loader: 'cache-loader', options: { cacheDirectory: '\\node_modules\\.cache\\vue-loader', cacheIdentifier: '5588e529' } }, { loader: 'vue-loader', options: { compilerOptions: { preserveWhitespace: false }, cacheDirectory: '\\node_modules\\.cache\\vue-loader', cacheIdentifier: '5588e529' } } ] }, /* config.module.rule('images') */ { test: /\.(png|jpe?g|gif|webp)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'img/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('svg') */ { test: /\.(svg)(\?.*)?$/, use: [ { loader: 'file-loader', options: { name: 'img/[name].[hash:8].[ext]' } } ] }, /* config.module.rule('media') */ { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'media/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('fonts') */ { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i, use: [ { loader: 'url-loader', options: { limit: 4096, fallback: { loader: 'file-loader', options: { name: 'fonts/[name].[hash:8].[ext]' } } } } ] }, /* config.module.rule('pug') */ { test: /\.pug$/, oneOf: [ /* config.module.rule('pug').oneOf('pug-vue') */ { resourceQuery: /vue/, use: [ { loader: 'pug-plain-loader' } ] }, /* config.module.rule('pug').oneOf('pug-template') */ { use: [ { loader: 'raw-loader' }, { loader: 'pug-plain-loader' } ] } ] }, /* config.module.rule('css') */ { test: /\.css$/, oneOf: [ /* config.module.rule('css').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('css').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('postcss') */ { test: /\.p(ost)?css$/, oneOf: [ /* config.module.rule('postcss').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] }, /* config.module.rule('postcss').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('scss') */ { test: /\.scss$/, oneOf: [ /* config.module.rule('scss').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] }, /* config.module.rule('scss').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('sass') */ { test: /\.sass$/, oneOf: [ /* config.module.rule('sass').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] }, /* config.module.rule('sass').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'sass-loader', options: { sourceMap: false, indentedSyntax: true } } ] } ] }, /* config.module.rule('less') */ { test: /\.less$/, oneOf: [ /* config.module.rule('less').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] }, /* config.module.rule('less').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'less-loader', options: { sourceMap: false } } ] } ] }, /* config.module.rule('stylus') */ { test: /\.styl(us)?$/, oneOf: [ /* config.module.rule('stylus').oneOf('vue-modules') */ { resourceQuery: /module/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('vue') */ { resourceQuery: /\?vue/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('normal-modules') */ { test: /\.module\.\w+$/, use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2, modules: true, localIdentName: '[name]_[local]_[hash:base64:5]' } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] }, /* config.module.rule('stylus').oneOf('normal') */ { use: [ { loader: 'vue-style-loader', options: { sourceMap: false, shadowMode: false } }, { loader: 'css-loader', options: { sourceMap: false, importLoaders: 2 } }, { loader: 'postcss-loader', options: { sourceMap: false } }, { loader: 'stylus-loader', options: { sourceMap: false, preferPathResolver: 'webpack' } } ] } ] }, /* config.module.rule('js') */ { test: /\.m?jsx?$/, exclude: [ function () { /* omitted long function */ } ], use: [ { loader: 'cache-loader', options: { cacheDirectory: '\\node_modules\\.cache\\babel-loader', cacheIdentifier: '23601776' } }, { loader: 'babel-loader' } ] }, /* config.module.rule('eslint') */ { enforce: 'pre', test: /\.(vue|(j|t)sx?)$/, exclude: [ /node_modules/, '\\node_modules\\@vue\\cli-service\\lib' ], use: [ { loader: 'eslint-loader', options: { extensions: [ '.js', '.jsx', '.vue' ], cache: true, cacheIdentifier: '413b12a3', emitWarning: true, emitError: false, eslintPath: '\\node_modules\\eslint', formatter: function () { /* omitted long function */ } } } ] } ] }, plugins: [ /* config.plugin('vue-loader') */ new VueLoaderPlugin(), /* config.plugin('define') */ new DefinePlugin( { 'process.env': { NODE_ENV: '"buildProd"', BASE_URL: '""' } } ), /* config.plugin('case-sensitive-paths') */ new CaseSensitivePathsPlugin(), /* config.plugin('friendly-errors') */ new FriendlyErrorsWebpackPlugin( { additionalTransformers: [ function () { /* omitted long function */ } ], additionalFormatters: [ function () { /* omitted long function */ } ] } ), /* config.plugin('hmr') */ new HotModuleReplacementPlugin(), /* config.plugin('progress') */ new ProgressPlugin(), /* config.plugin('html') */ new HtmlWebpackPlugin( { templateParameters: function () { /* omitted long function */ }, template: '\\public\\index.html' } ), /* config.plugin('preload') */ new PreloadPlugin( { rel: 'preload', include: 'initial', fileBlacklist: [ /\.map$/, /hot-update\.js$/ ] } ), /* config.plugin('prefetch') */ new PreloadPlugin( { rel: 'prefetch', include: 'asyncChunks' } ), /* config.plugin('copy') */ new CopyWebpackPlugin( [ { from: '\\public', to: '\\dist', toType: 'dir', ignore: [ '.DS_Store', { glob: 'index.html', matchBase: false } ] } ] ), { options: { filename: 'webpack-assets.json', prettyPrint: false, update: false, fullPath: true, manifestFirst: true, useCompilerPath: false, fileTypes: [ 'js', 'css' ], includeAllFileTypes: true, keepInMemory: false, integrity: false, metadata: { version: '2_2_1' }, processOutput: function (assets) { return JSON.stringify(assets, null, options.prettyPrint ? 2 : null); } }, writer: function () { /* omitted long function */ } } ], entry: { app: [ './src/main.js', 'babel-polyfill', 'classlist-polyfill' ] }, optimization: { minimize: true, minimizer: [ { options: { test: /\.m?js(\?.*)?$/i, warningsFilter: () => true, extractComments: true, sourceMap: true, cache: true, cacheKeys: defaultCacheKeys => defaultCacheKeys, parallel: true, include: undefined, exclude: undefined, minify: undefined, terserOptions: { ecma: undefined, warnings: false, parse: {}, compress: { drop_console: true, drop_debugger: true, pure_funcs: [ 'console.log' ] } } } } ] } }
打包后去不掉console和debugger
运行vue -V
使用这种方式
chainWebpack: (config) => { config.optimization.minimizer('terser').tap((args) => { args[0].terserOptions.compress.drop_console = true return args }) }
报错:
config.optimization.minimizer(...).tap is not a function