|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- const path = require('path');
- const defaultSettings = require('./src/config/index.js');
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
-
- const resolve = dir => path.join(__dirname, dir);
-
- const name = defaultSettings.title || '';
-
- const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);
-
- const { defineConfig } = require('@vue/cli-service');
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- module.exports = defineConfig({
- publicPath: './',
-
- outputDir: 'dist',
- assetsDir: 'static',
- lintOnSave: !IS_PROD,
- productionSourceMap: false,
- devServer: {
- port: 9093,
- open: false,
- client: {
- overlay: {
-
- warnings: false,
- errors: true
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- },
- css: {
- extract: IS_PROD,
- sourceMap: false,
- loaderOptions: {
- scss: {
-
-
- additionalData: `
- @import "assets/css/mixin.scss";
- @import "assets/css/variables.scss";
- $cdn: "${defaultSettings.$cdn}";
- `
- }
- }
- },
- configureWebpack: config => {
- config.name = name;
-
-
-
-
-
-
- },
-
- chainWebpack: config => {
-
-
-
-
- config.resolve.alias
- .set('@', resolve('src'))
- .set('assets', resolve('src/assets'))
- .set('api', resolve('src/api'))
- .set('views', resolve('src/views'))
- .set('components', resolve('src/components'));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- config.module
- .rule('vue')
- .use('vue-loader')
- .loader('vue-loader')
- .tap(options => {
- options.compilerOptions.preserveWhitespace = true;
- return options;
- })
- .end();
-
-
- if (IS_PROD) {
- config.plugin('webpack-report').use(BundleAnalyzerPlugin, [
- {
- analyzerMode: 'static'
- }
- ]);
- }
- config
-
- .when(!IS_PROD, config => config.devtool('cheap-source-map'));
-
- config.when(IS_PROD, config => {
- config.optimization.splitChunks({
- chunks: 'all',
- cacheGroups: {
-
- commons: {
- name: 'chunk-commons',
- test: resolve('src/components'),
- minChunks: 3,
- priority: 5,
- reuseExistingChunk: true
- },
- node_vendors: {
- name: 'chunk-libs',
- chunks: 'initial',
- test: /[\\/]node_modules[\\/]/,
- priority: 10
- },
- vantUI: {
- name: 'chunk-vantUI',
- priority: 20,
- test: /[\\/]node_modules[\\/]_?vant(.*)/
- }
- }
- });
- config.optimization.runtimeChunk('single');
- });
- }
- });
|