123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- 'use strict'
- const { defineConfig } = require('@vue/cli-service')
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
- // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
- // 配置编辑器
- const Timestamp = new Date().getTime()
- module.exports = defineConfig({
- // 项目部署的基本路径,默认 '/'
- publicPath: '/',
- assetsDir: 'static',
- // 项目打包是否生成js的 source map 调试包,默认 true,生产部署设置为false
- productionSourceMap: process.env.NODE_ENV !== 'production',
- // productionSourceMap: false,
- // devServer 支持 webpack-dev-server 所有选项
- devServer: {
- open: true,
- // host: 'localhost',
- port: 9000,
- hot: true,
- // https: false,
- proxy: {
- '/op/base': {
- // target: 'http://192.168.3.162:7654',
- target: 'https://company.citupro.com:18182/op/base',
- secure: false, // 是否支持 https,默认 false
- changeOrigin: true, // 是否支持跨域
- headers: {
- // 确保包含这些头部以兼容IE11
- Accept: 'application/json',
- 'Content-Type': 'application/json; charset=utf-8'
- },
- onProxyReq (proxyReq) {
- // 对于IE11的特殊处理
- if (proxyReq.getHeader('origin')) {
- proxyReq.setHeader('origin', 'https://company.citupro.com:18182/op/base')
- }
- },
- pathRewrite: {
- '^/op/base': ''
- }
- },
- '/op/base/api': {
- // target: 'http://192.168.3.162:7654',
- target: 'https://company.citupro.com:18183',
- secure: false, // 是否支持 https,默认 false
- changeOrigin: true, // 是否支持跨域
- headers: {
- // 确保包含这些头部以兼容IE11
- Accept: 'application/json',
- 'Content-Type': 'application/json; charset=utf-8'
- },
- onProxyReq (proxyReq) {
- // 对于IE11的特殊处理
- if (proxyReq.getHeader('origin')) {
- proxyReq.setHeader('origin', 'https://company.citupro.com:18183')
- }
- },
- pathRewrite: {
- '^/op/base/api': '/op/base/api'
- }
- }
- }
- },
- configureWebpack: config => {
- config.devtool = 'source-map'
- // 代码拆分
- config.optimization.splitChunks.chunks = 'all'
- config.entry.app = ['core-js/stable', 'regenerator-runtime/runtime', './src/main.js']
- // 代码拆分配置
- // config.optimization.splitChunks = {
- // chunks: 'all',
- // cacheGroups: {
- // vendors: {
- // test: /[\\/]node_modules[\\/]/,
- // priority: -10,
- // name: 'vendors'
- // },
- // common: {
- // minChunks: 2,
- // priority: -20,
- // reuseExistingChunk: true
- // }
- // }
- // }
- config.output.filename = `static/js/[name].${Timestamp}.js`
- config.output.chunkFilename = `static/js/[name].${Timestamp}.js`
- config.module.rules.push(
- {
- test: /\.geojson$/,
- loader: 'json-loader',
- type: 'javascript/auto'
- },
- // 其他加载器规则...
- {
- test: /\.jade$/,
- loader: 'jade'
- },
- {
- test: /\.pug$/,
- loader: 'pug-plain-loader'
- }
- )
- if (process.env.NODE_ENV === 'production') {
- config.plugins.push(
- new UglifyJsPlugin({
- uglifyOptions: {
- compress: {
- drop_console: true,
- drop_debugger: true
- },
- output: {
- comments: false
- }
- },
- sourceMap: false,
- parallel: true
- }))
- }
- },
- chainWebpack: config => {
- config.when(process.env.NODE_ENV !== 'development', config => {
- config.optimization.minimizer('terser').tap(options => {
- options[0].terserOptions.compress.drop_console = true
- options[0].terserOptions.output = {
- comments: false
- }
- return options
- })
- })
- },
- // babel-loader 是否处理 node_modules 中的依赖包,处理哪些依赖包,参数类型: boolean | Array<string | RegExp>
- transpileDependencies: [
- // /[\\/]node_modules[\\/]/ // 转译所有 node_modules 中的依赖
- // Vue 相关
- // 'vue',
- // 'vuex',
- // 'vue-router',
- // UI 组件库
- 'element-ui',
- // 'async-validator',
- // 编辑器
- '@wangeditor/editor',
- '@wangeditor/editor-for-vue',
- // '@mdi/font',
- // 'scrolling-element',
- // // 其他可能包含 ES6 代码的依赖
- 'fs',
- 'axios',
- 'lodash',
- // 移除 'echarts' 以避免模块转换问题
- 'decimal.js',
- 'nprogress',
- 'element-resize-detector',
- // // 使用正则匹配更广泛的包
- /node_modules\/@wangeditor/
- // /node_modules\/vue-/,
- // /node_modules\/element-ui/,
- // 注释掉 echarts 相关的转译配置
- // /node_modules\/echarts/
- ],
- // 移除console
- terser: {
- terserOptions: {
- compress: {
- drop_console: true,
- drop_debugger: true
- }
- }
- },
- css: {
- loaderOptions: {
- sass: {
- additionalData: `
- @import "@/styles/config.scss";
- `
- }
- }
- }
- })
|