'use strict' const path = require('path') // Node.js的path模块提供了一些用于处理文件路径的小工具 const settings = require('./src/settings.js') const name = settings.title // 页面标题 const port = process.env.port || process.env.npm_config_port || 8081 // dev端口号 function resolve(dir) { return path.join(__dirname, dir) // 连接路径,会正确使用当前系统的路径分隔符,Unix系统是"/",Windows系统是"\" } // 所有配置项详情请前往 https://cli.vuejs.org/config 查看 module.exports = { /** * 如果计划在子路径下部署站点,则需要设置publicPath * 例如,如果计划将站点部署到https://foo.github.io/bar/,那么publicPath应该设置为“/bar/”。在多数情况下,请使用“/”!! * 详情参考: https://cli.vuejs.org/config/#publicpath */ publicPath: './', outputDir: 'dist', //输出目录 assetsDir: 'static', //编译文件存放目录 lintOnSave: process.env.NODE_ENV === 'development', //dev环境保存时eslint校验 productionSourceMap: false, //prod环境不启用sourceMap devServer: { port: port, disableHostCheck: true, proxy: { '/api': { target: 'http://192.168.0.43:8181/', // 测试服 // target: 'http://26t13m1315.wicp.vip:32471/cae/service/TransServlet/',//黄工接口调用地址 // target: 'http://192.168.0.42:8081/', // 亮哥 // target: 'http://192.168.0.15:8081/', // 喻泽 // target: 'http://26t13m1315.wicp.vip:32470/', // 测试服 // target: 'http://192.168.0.43:8181/', // 测试服 //target: 'http://192.168.0.140:32470/', // 测试服 // target: ' https://www.xigital.com.cn/cae/service/', // 测试服 secure: false, //接受使用https changeOrigin: true, //允许跨域 ws: false, //使用websocket pathRewrite: { // 路径重写 '^/api': '' } }, '/stage-api': { target: 'http://192.168.0.140:32470/', changeOrigin: true, secure: false, pathRewrite: { '^/stage-api': '/' } } }, open: false, //不自动打开浏览器 overlay: { warnings: false, errors: true }, // before: require('./mock/mock-server.js') }, configureWebpack: { // 创建别名(在webpack的name字段中提供别名,以便在index.html中插入正确的引用路径) name: name, resolve: { alias: { '@': resolve('src') } } }, chainWebpack(config) { config.plugins.delete('preload') // TODO: need test config.plugins.delete('prefetch') // TODO: need test // 设置 svg-sprite-loader 插件生效文件夹(src/icons) 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() // 设置 preserveWhitespace config.module .rule('vue') .use('vue-loader') .loader('vue-loader') .tap(options => { options.compilerOptions.preserveWhitespace = true return options }) .end() // config.module // .rule('THREE') // .use('imports-loader?THREE=three') // .loader('imports-loader') // .end() // config.module // .rule('OrbitControls”') // .use('exports-loader?THREE.OrbitControls') // .loader('exports-loader') // .end() // webpack的SourceMaps 7种打包编译模式详见 https://webpack.js.org/configuration/devtool/#development config .when(process.env.NODE_ENV === 'development', config => config.devtool('cheap-source-map') // 生成一个没有列信息(column-mappings)的SourceMaps文件,不包含loader的sourcemap(譬如babel的sourcemap) ) config .when(process.env.NODE_ENV !== 'development', config => { config .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ // `runtime` 必须与runtimeChunk名称相同,默认值为`runtime` inline: /runtime\..*\.js$/ }]) .end() config .optimization.splitChunks({ chunks: 'all', cacheGroups: { libs: { name: 'chunk-libs', test: /[\\/]node_modules[\\/]/, priority: 10, chunks: 'initial' // 仅打包最初的第三方依赖 }, elementUI: { name: 'chunk-elementUI', // 将elementUI拆分为一个包 priority: 20, // weight必须大于libs和app,否则将打包成libs或app test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // 为了适应cnpm }, commons: { name: 'chunk-commons', test: resolve('src/components'), // 可以自定义规则 minChunks: 3, // 最小公共数 priority: 5, reuseExistingChunk: true } } }) config.optimization.runtimeChunk('single') } ) } }