const path = require('path') const TerserPlugin = require('terser-webpack-plugin') module.exports = { publicPath: process.env.VUE_APP_PUBLIC_PATH, lintOnSave: process.env.NODE_ENV !== 'production', // 不输出为编译警告 runtimeCompiler: true, productionSourceMap: false, devServer: { // proxy: 'http://test.cspg_api.ecspg.com/public/index.php/' // '/': { // target: 'http://test.cspg_api.ecspg.com/public/index.php/', // changeOrigin: true // } }, configureWebpack: { resolve: { alias: { // 确保路径解析正确 'html2canvas': 'html2canvas/dist/html2canvas.min.js' } } }, chainWebpack: (config) => { // babel-polyfill 加入 entry const entry = config.entry('app') entry .add('babel-polyfill') .end() config.plugins.delete('preload') // TODO: need test config.plugins.delete('prefetch') // TODO: need test config.optimization.minimizer([ new TerserPlugin({ terserOptions: { compress: { // turn off flags with small gains to speed up minification arrows: false, collapse_vars: false, // 0.3kb comparisons: false, computed_props: false, hoist_funs: false, hoist_props: false, hoist_vars: false, inline: false, loops: false, negate_iife: false, properties: false, reduce_funcs: false, reduce_vars: false, switches: false, toplevel: false, typeofs: false, // a few flags with noticable gains/speed ratio // numbers based on out of the box vendor bundle booleans: true, // 0.7kb if_return: true, // 0.4kb sequences: true, // 0.7kb unused: true, // 2.3kb // required features to drop conditional branches conditionals: true, dead_code: true, evaluate: true, drop_console: true }, mangle: { safari10: true } }, sourceMap: false, cache: true, parallel: true }) ]) }, css: { // 不生成cssMap文件,生成map文件方便调试 sourceMap: false, loaderOptions: { less: { // @是src的别名 data: '@import "@/styles/color.less";' } } }, // 加载less全局变量 https://cli.vuejs.org/zh/guide/css.html#%E9%A2%84%E5%A4%84%E7%90%86%E5%99%A8 // 第三方插件 pluginOptions: { 'style-resources-loader': { preProcessor: 'less', patterns: [path.resolve(__dirname, 'src/styles/color.less')] } } }