const path = require('path') const minify = process.env.NODE_ENV === 'development' ? false : { collapseWhitespace: true, removeComments: true, removeRedundantAttributes: true, removeScriptTypeAttributes: true, removeStyleLinkTypeAttributes: true, useShortDoctype: true, minifyCSS: true, minifyJS: true } function resolve(dir) { return path.join(__dirname, dir) } module.exports = { publicPath: '/', lintOnSave: true, runtimeCompiler: true, pages: { index: { entry: 'src/main.js', template: 'public/index.html', filename: 'index.html', chunks: ['chunk-vendors', 'chunk-common', 'index'], minify }, preview: { entry: 'src/views/preview/main.js', template: 'public/preview.html', filename: 'preview.html', chunks: ['chunk-vendors', 'chunk-common', 'preview'], minify } }, pluginOptions: { 'style-resources-loader': { preProcessor: 'less', patterns: [ path.resolve(__dirname, './src/styles/variables.less') ] } }, devServer: { proxy: { '/api': { target: 'https://wy-test.huiguanjia.cn/9ad134a361f8d778/', // 对应自己的接口 changeOrigin: true, ws: false, pathRewrite: { '^/api': '' } } }, overlay: { // 错误信息显示到浏览器上 warnings: false, errors: true } }, css: { // 开启样式追溯 sourceMap: true }, productionSourceMap: false, chainWebpack(config) { config.resolve.alias.set('@', resolve('src')) // set svg-sprite-loader config.module .rule('svg') .exclude.add(resolve('src/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() } }