123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- const path = require('path')
- const resolve = (dir) => {
- return path.join(__dirname, dir)
- }
- let argvs = process.argv.filter((e) => e.includes('='))
- for (const iterator of argvs) {
- let diyArg = iterator.split('=')
- process.env['VUE_APP_' + diyArg[0].slice(2)] = diyArg[1]
- }
- process.env.VUE_APP_ENV = process.env.VUE_APP_ENV || process.env.NODE_ENV
- const env = require('./env')
- const config = require('./src/config')
- process.env.VUE_APP_TITLE = config.SYSTEM_NAME
- process.env.VUE_APP_PACKETTIME = new Date().toLocaleString()
- let pages = {
- index: {
-
- entry: 'src/main.js',
-
- template: 'public/index.html',
-
- filename: 'index.html',
-
-
-
-
-
- chunks: ['chunk-libs', 'chunk-vant', 'chunk-commons', 'runtime', 'index'],
- },
- subpage: {
- entry: 'src/main.js',
- template: 'public/index-wx.html',
- filename: 'index-wx.html',
- chunks: ['chunk-libs', 'chunk-vant', 'chunk-commons', 'runtime', 'index'],
- },
- }
- let setting = {
- publicPath: env.BASE_URL || '/',
- outputDir: 'dist',
-
- productionSourceMap: false,
- pages,
-
- lintOnSave: false,
-
- devServer: {
- host: '0.0.0.0',
- port: 8082,
-
- open: true,
- proxy: {
-
- ['/api']: {
- target: env.BASE_API,
- changeOrigin: true,
- pathRewrite: {
- ['^/api']: '',
- },
- },
- },
- disableHostCheck: true,
- },
- pluginOptions: {
- 'style-resources-loader': {
- preProcessor: 'less',
- patterns: [path.resolve(__dirname, './src/styles/varibles.less')],
- },
- },
- css: {
- loaderOptions: {
- less: {
- modifyVars: {
-
-
- hack: `true; @import "${path.resolve(__dirname, './src/styles/varibles.less')}";`,
- },
- },
- },
- },
- configureWebpack: {
- resolve: {
- alias: {
- '@': resolve('src'),
- },
- },
- },
- chainWebpack(config) {
-
- config.module
- .rule('svg')
- .exclude.add(resolve('src/assets/icons'))
- .end()
- config.module
- .rule('icons')
- .test(/\.svg$/)
- .include.add(resolve('src/assets/icons'))
- .end()
- .use('svg-sprite-loader')
- .loader('svg-sprite-loader')
- .options({
- symbolId: 'icon-[name]',
- })
- .end()
- config.when(process.env.NODE_ENV !== 'development', (config) => {
- Object.keys(pages).forEach((element) => {
- config.plugin('preload-' + element).tap(() => [
- {
- rel: 'preload',
-
- fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/, /subpage\./],
- include: 'initial',
- },
- ])
- config
- .plugin('ScriptExtHtmlWebpackPlugin')
- .after('html-' + element)
- .use('script-ext-html-webpack-plugin', [
- {
-
- inline: /runtime\..*\.js$/,
- },
- ])
- .end()
- config.plugins.delete('prefetch-' + element)
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- config.optimization.minimizer('terser').tap((options) => {
- options[0].terserOptions.compress.drop_console = false
- options[0].terserOptions.compress.drop_debugger = true
- return options
- })
- config.optimization.splitChunks({
- chunks: 'all',
-
-
- cacheGroups: {
- alioss: {
- name: 'chunk-ali-oss',
- priority: 30,
- test: /[\\/]node_modules[\\/]_?ali-oss(.*)/,
- },
- vant: {
- name: 'chunk-vant',
- priority: 20,
- test: /[\\/]node_modules[\\/]_?vant(.*)/,
- },
- libs: {
- name: 'chunk-libs',
- test: /[\\/]node_modules[\\/]/,
- priority: 10,
- chunks: 'initial',
- enforce: true,
- },
-
-
-
-
-
-
-
- },
- })
- config.optimization.runtimeChunk('single')
- process.env.npm_config_report &&
- config
- .plugin('webpack-bundle-analyzer')
- .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [
- {
- analyzerMode: 'static',
- },
- ])
- .end()
- })
- },
- }
- process.env.NODE_ENV === 'development' && delete setting.pages
- module.exports = { ...setting }
|