const path = require('path') function join (dir) { return path.join(__dirname, dir) } // 打包文件位置 function diffOutputDir () { if (process.env.NODE_ENV === 'development') { return './dist' } else if (process.env.NODE_ENV === 'production') { return './jinshui-screen' } } // 生产环境-资源引用路径 function diffPublicPath () { if (process.env.NODE_ENV === 'development') { return './' } else if (process.env.NODE_ENV === 'production') { return './' } } module.exports = { // 资源根路径 publicPath: diffPublicPath(), // 打包根路径 outputDir: diffOutputDir(), // 静态资源文件夹名 assetsDir: 'static', // 保存时是否使用 eslint-loader lintOnSave:false, // 生产环境 source map productionSourceMap: false, // 调整 webpack 配置 chainWebpack: config => { config.plugins.delete('prefetch') config.resolve.alias .set('api', join('src/api')) .set('assets', join('src/assets')) .set('components', join('src/components')) .set('directives', join('src/directives')) .set('directives', join('src/directives')) .set('style', join('src/style')) .set('utils', join('src/utils')) .set('views', join('src/views')) config.module .rule('svg') .include.add(join('src/components/svg-icon/svg')) .end() .test(/\.svg$/) .use('file-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) // 修复HMR config.resolve.symlinks(true) // 打包结果分析 if (process.env.NODE_ENV === 'development') { config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin) } }, // 调整 webpack 配置 configureWebpack: config => { config.devtool = process.env.NODE_ENV === 'production' ? 'none' : 'cheap-eval-source-map' if (process.env.NODE_ENV === 'production') { config.externals = { echarts: 'echarts', vue: 'Vue', 'element-ui': 'ELEMENT' } } else { config.externals = { echarts: 'echarts' } } }, // css 相关 css: { // 将组件内的 css 提取到 一个单独的文件 // extract: true, // 是否开启 css source map sourceMap: false, // 为预处理器的 loader 传递自定义选项 loaderOptions: {} }, // 开发环境 dev-server devServer: { open: false, host: '0.0.0.0', port: 9090, proxy: { '/api': { target: 'http://127.0.0.1:10001/api/', pathRewrite: { '^/api': '' }, logLevel: 'debug', changeOrigin: true, secure: false } }, https: false, hotOnly: true, before: app => {} } }