123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- const path = require('path');
- const webpack = require('webpack');
- const createThemeColorReplacerPlugin = require('./config/plugin.config');
- // npm install --save-dev hard-source-webpack-plugin
- const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
- const {blue} = require("@ant-design/colors")
- function resolve(dir) {
- return path.join(__dirname, dir);
- }
- const CompressionPlugin = require("compression-webpack-plugin");
- const isProd = process.env.NODE_ENV === 'production'; // process.env.NODE_ENV === 'production';
- const Timestamp = new Date().getTime();
- const assetsCDN = {
- // webpack build externals
- externals: {
- vue: 'Vue',
- 'vue-router': 'VueRouter',
- vuex: 'Vuex',
- axios: 'axios'
- },
- css: [],
- // https://unpkg.com/browse/vue@2.6.10/
- js: [
- '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
- '//cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
- '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
- '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js'
- ]
- };
- // vue.config.js
- const vueConfig = {
- publicPath: process.env.VUE_APP_MERGE == 1 ? process.env.VUE_APP_BASE_URL_FM : '',
- configureWebpack: {
- // webpack plugins
- plugins: [
- // Ignore all locale files of moment.js
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
- ]
- },
- chainWebpack: config => {
- // 开发环境,cach能减少run dev,run build的70%的运行时间
- // production 环境,由于文件需要加时间戳,导致缓存没有意义。去掉随机文件名的配置,可以减少60%的打包时间。
- // 最终,开发环境,加载cach插件;production环境,不加载!
- if (!isProd) {
- config.plugin('cache').use(HardSourceWebpackPlugin);
- // config.cache(true);
- }
- // 移除prefetch插件,避免加载多余的资源
- config.plugins.delete('prefetch');
- if (isProd) {
- config.output.filename('js/[name].' + Timestamp + '.js').end();
- config.output.chunkFilename('js/[name].' + Timestamp + '.js').end();
- config.plugin('extract-css').tap(args => [
- {
- filename: `css/[name].${Timestamp}.css`,
- chunkFilename: `css/[name].${Timestamp}.css`
- }
- ]);
- }
- config.resolve.alias.set('@$', resolve('src'));
- const svgRule = config.module.rule('svg');
- svgRule.uses.clear();
- svgRule
- .oneOf('inline')
- .resourceQuery(/inline/)
- .use('vue-svg-icon-loader')
- .loader('vue-svg-icon-loader')
- .end()
- .end()
- .oneOf('external')
- .use('file-loader')
- .loader('file-loader')
- .options({
- name: 'assets/[name].[hash:8].[ext]'
- });
- // if prod is on
- // assets require on cdn
- if (isProd) {
- config.plugin('html').tap(args => {
- args[0].cdn = assetsCDN;
- return args;
- });
- }
- if (process.env.NODE_ENV === 'production') {
- config.plugin('compressionPlugin').use(
- new CompressionPlugin({
- filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
- algorithm: 'gzip', // 使用gzip压缩
- test: /\.(js|css|less)$/, // 匹配文件名
- threshold: 10240, // 对超过10k的数据压缩
- minRatio: 0.8, // 压缩率小于0.8才会压缩
- deleteOriginalAssets: true // 删除源文件
- }));
- }
- },
- css: {
- loaderOptions: {
- less: {
- modifyVars: {
- 'primary-color': '#002FA7',
- 'border-radius-base': '10px',
- // 面包屑
- 'breadcrumb-base-color': '#fff',
- 'breadcrumb-separator-color': '#fff',
- 'breadcrumb-link-color-hove': '#fff',
- 'breadcrumb-last-item-color': '#fff',
- 'breadcrumb-link-color': '#fff',
- 'breadcrumb-font-size': '15px',
- // 面包屑
- // ****** 左侧菜单 ******
- //菜单背景颜色
- 'menu-dark-bg': 'linear-gradient(to right, #215278, #21527F, #215288, #21528A, #21528A, #21528A, #215288, #21527F, #215278)',
- //子菜单颜色
- 'menu-dark-submenu-bg': 'linear-gradient(#215278, #21527F, #215288, #21528A, #21528A, #21528A, #215288, #21527F, #215278)',
- 'menu-icon-size': '15px',
- 'menu-icon-size-lg': '16px',
- 'menu-item-active-bg': '#ffffff',
- 'menu-dark-highlight-color': '#6b89ff',
- 'menu-dark-item-active-bg': '#fff',
- 'menu-dark-selected-item-icon-color': '#a4009d',
- 'menu-dark-selected-item-text-color': '#1890ff',
- 'menu-dark-popup-bg': '#fff',
- 'menu-dark-color': '#fff',
- // ****** 左侧菜单 ******
- //卡片
- 'card-radius': '10px',
- },
- // DO NOT REMOVE THIS LINE
- javascriptEnabled: true
- }
- }
- },
- // disable source map in production
- productionSourceMap: process.env.NODE_ENV === 'development', //process.env.NODE_ENV === 'development' ? true : false
- lintOnSave: false,
- // babel-loader no-ignore node_modules/*
- transpileDependencies: [],
- devServer: {
- host: 'localhost',
- port: 8081,
- disableHostCheck: true,
- proxy: {
- "/DFMEA": {
- target: "http://localhost:8082",//接口的地址
- // target: "http://139.196.74.209:8090",//接口的地址
- changeOrigin: true
- // pathRewrite: {
- // "^/DFMEA": ""
- // }
- }
- }
- }
- };
- // preview.pro.loacg.com only do not use in your production;
- if (process.env.VUE_APP_PREVIEW === 'true') {
- // add `ThemeColorReplacer` plugin to webpack plugins
- vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin());
- }
- module.exports = vueConfig;
|