const path = require("path"); const webpack = require("webpack") // const TerserPlugin = require('terser-webpack-plugin'); const isProduction = process.env.NODE_ENV === 'production'; function resolve(dir) { return path.join(__dirname, dir); } module.exports = { // 基本路径 publicPath: process.env.NODE_ENV === 'production' ? '/' + process.env.VUE_APP_ORDERURL + '/' : '/', // 输出文件目录 outputDir: process.env.VUE_APP_ORDERURL, lintOnSave: false, filenameHashing: true, //生产环境下的打包文件的哈希后缀,默认true,哈希后缀是为了浏览器缓存 // webpack配置 - 简单配置方式 configureWebpack: config => { config.plugins.push( new webpack.DllReferencePlugin({ context: process.cwd(), manifest: require('./public/vendor/vendor-manifest.json') }), new webpack.LoaderOptionsPlugin({ // test: /\.xxx$/, // may apply this only for some modules options: { pluginOptions: { // 第三方插件配置 'style-resources-loader': { preProcessor: 'less', patterns: [path.resolve(__dirname, './src/assets/less/index.less')] // less所在文件路径 } } } }) ); if (isProduction) { // 为生产环境修改配置... //生产环境自动删除console config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log'] } }, chainWebpack: config => { config.resolve.alias .set('@', resolve('src')) .set('@views', resolve('src/views')) .set('@assets', resolve('src/assets')) .set('@common', resolve('src/common')) .set('components', resolve('src/common/components')) .set('mixins', resolve('src/common/mixins')); config.plugin('provide').use(webpack.ProvidePlugin, [{ $: 'jquery', jquery: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery' }]); // const types = ["vue-modules", "vue", "normal-modules", "normal"] // types.forEach(type => // addStyleResource(config.module.rule("less").oneOf(type)) // ); }, devServer: { port: '9000', open: false, //项目启动时是否自动打开浏览器,我这里设置为false,不打开,true表示打开 proxy: { //订单服务 '/sims-api': { // target: 'http://10.1.31.166:18107/sims-api', // 张双超 // target: 'http://10.1.30.104:18108/sims-api', // 姚旭光 target: 'http://10.18.90.125:10000/sims-api', // 测试环境 changeOrigin: false, // target: 'http://10.1.3.216:10000/sims-api', //乐企通 pathRewrite: { '^/sims-api': '/' }, }, '/management': { target: 'http://10.18.90.125:10000/management', // 新测试环境 // target: 'http://10.1.3.216:10000/management', //乐企通 changeOrigin: false, pathRewrite: { '^/management': '/', } } } } } function addStyleResource(rule) { rule .use("style-resource") .loader("style-resources-loader") .options({ patterns: [ path.resolve(__dirname, "src/assets/less/index.less") // 需要全局导入的less ] }) }