123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- const path = require("path");
- // npm install --save-dev hard-source-webpack-plugin
- const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
- // function resolve(dir) {
- // return path.join(__dirname, dir)
- // }
- const CompressionPlugin = require("compression-webpack-plugin");
- const isProd = process.env.NODE_ENV === "production";
- const Timestamp = new Date().getTime();
- const webpack = require("webpack");
- module.exports = {
- configureWebpack: {
- // 支持全局jquery
- plugins: [
- new webpack.ProvidePlugin({
- $: "jquery",
- jQuery: "jquery",
- "windows.jQuery": "jquery"
- })
- ]
- },
- assetsDir: "assets",
- publicPath:
- process.env.VUE_APP_MERGE == 1
- ? process.env.VUE_APP_BASE_URL_MFE + "/"
- : "", //合并三个应用
- lintOnSave: false,
- productionSourceMap: process.env.NODE_ENV == "development" ? true : false, //process.env.NODE_ENV == 'development' ? true : false
- pluginOptions: {
- "style-resources-loader": {
- preProcessor: "less",
- patterns: [path.resolve(__dirname, "src/styles/mixins.less")]
- }
- },
- 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.module
- .rule("fonts")
- .use("url-loader")
- .loader("url-loader")
- .tap((options) => {
- options["limit"] = 4096;
- options["publicPath"] = process.env.VUE_APP_BASE_URL_MFE + "/"; // **重点:添加路径
- return options;
- });
- // if prod is on
- // assets require on cdn
- // if (isProd) {
- // //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': '#1890ff',
- 'font-family': '宋体',
- 'border-radius-base': '4px',
- 'link-color': '#1890FF',
- 'btn-border-radius-base': '4px',
- 'btn-default-bg': '#FFFFFF',
- 'btn-default-border': '#1890ff',
- 'btn-default-color': '#1890FF',
- 'btn-disable-color': '#9C9FAC',
- 'select-border-color': '#CED0D8',
- 'select-item-active-bg': '#F5F6F7',
- 'select-item-selected-bg': '#F6F7FA',
- 'select-dropdown-line-height': '#F6F7FA',
- 'layout-header-height': '56px',
- 'layout-body-background': '#FFFFFF', //底背景色,原为默认灰底
- 'table-row-hover-bg': '#F5F6F7',
- 'form-item-trailing-colon': 'false',
- 'label-color': '#41475E',
- 'input-bg': '#FFFFFF',
- 'input-border-color': '#CED0D8',
- 'card-background': '#FFFFFF',
- 'card-radius': '4px',
- 'card-skeleton-bg': '#9C9FAC',
- 'table-row-hover-bg': '#fafafa',
- 'form-item-margin-bottom': '0px',
- },
- javascriptEnabled: true
- }
- }
- },
- devServer: {
- host: 'localhost',
- port: 8084,
- disableHostCheck: true,
- proxy: {
- "/DFMEA": {
- target: "http://localhost:8082",//接口的地址
- // target: "http://1.117.58.199:8090",//接口的地址
- changeOrigin: true,
- pathRewrite: {
- "^/DFMEA": "/DFMEA"
- }
- }
- }
- }
- };
|