zhgdyun/vue.config.js

173 lines
5.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
// 代码压缩
const TerserPlugin = require("terser-webpack-plugin");
function addStyleResource(rule) {
rule
.use("style-resource")
.loader("style-resources-loader")
.options({
patterns: [
path.resolve(__dirname, "src/assets/style/var.less"), //全局引入的less文件
path.resolve(__dirname, "src/assets/style/longguang.less"), //全局引入的less文件--龙光地产
],
});
}
module.exports = {
// publicPath: process.env.NODE_ENV === "production" ? "/jxjgd" : "/jxjgd",//金林湾配置
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
devServer: {
// host: 'localhost',
proxy: {
"/china": {
target: "http://122.112.239.62:9000",
changeOrigin: true,
pathRewrite: {
"^/china": "", //重写路径
},
'/img_w/wmts': {
target: 'https://t5.tianditu.gov.cn',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/img_w/wmts': '/img_w/wmts'
}
},
}
},
},
pages: {
index: {
entry: "./src/pages/index/index.js",
template: "./src/pages/index/index.html",
filename: "index.html",
title: "机械设备管理平台",
},
equipmentCenter: {
entry: "./src/pages/equipmentCenter/equipmentCenter.js",
template: "./src/pages/equipmentCenter/equipmentCenter.html",
filename: "equipmentCenter.html",
title: "设备中台",
},
},
chainWebpack: (config) => {
const types = ["vue-modules", "vue", "normal-modules", "normal"];
types.forEach((type) =>
addStyleResource(config.module.rule("less").oneOf(type))
);
},
pluginOptions: {
"style-resources-loader": {
preProcessor: "stylus",
patterns: [],
},
},
productionSourceMap: false,
configureWebpack: config => {
config.module.rules.push({
test: /\.js$/,
include: path.resolve(__dirname, 'packages'),
use: [
{
loader: 'babel-loader',
options: {
// Babel options here
}
}
]
});
config.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ["console.log"], // 移除console
},
},
}),
],
};
config.devtool = 'source-map';
const cesiumSourcePath = 'node_modules/mars3d-cesium/Build/Cesium/'; // cesium库安装目录
const cesiumRunPath = './mars3d-cesium/'; // cesium运行时路径
const plugins = [
// 标识cesium资源所在的主目录cesium内部资源加载、多线程等处理时需要用到
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(path.join(config.output.publicPath, cesiumRunPath))
}),
// Cesium相关资源目录需要拷贝到系统目录下面部分CopyWebpackPlugin版本的语法可能没有patterns
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSourcePath, 'Workers'), to: path.join(config.output.path, cesiumRunPath, 'Workers') },
{ from: path.join(cesiumSourcePath, 'Assets'), to: path.join(config.output.path, cesiumRunPath, 'Assets') },
{ from: path.join(cesiumSourcePath, 'ThirdParty'), to: path.join(config.output.path, cesiumRunPath, 'ThirdParty') },
{ from: path.join(cesiumSourcePath, 'Widgets'), to: path.join(config.output.path, cesiumRunPath, 'Widgets') }
]
}),
new NodePolyfillPlugin()
];
config.module.rules.push({
test: /\.js$/,
enforce: 'pre',
include: path.resolve(__dirname, 'node_modules/cesium/Source'),
sideEffects: false,
use: [
{
loader: 'strip-pragma-loader',
options: {
pragmas: {
debug: false
}
}
}
]
});
config.plugins = config.plugins.concat(plugins);
},
// configureWebpack: (config) => {
// Object.assign(config, {
// // 开发生产共同配置
// resolve: {
// alias: {
// '@': path.resolve(__dirname, './src'),
// '@c': path.resolve(__dirname, './src/components'),
// '@p': path.resolve(__dirname, './src/assets/j')
// } // 别名配置
// }
// })
// }
css: {
// extract: true, // 是否使用css分离插件 ExtractTextPlugin(跟热加载冲突)
sourceMap: true, // 开启 CSS source maps
loaderOptions: {
less: {
modifyVars: {
'primary-color': '#4C6CEC',
'link-color': '#4C6CEC',
'border-radius-base': '2px',
},
javascriptEnabled: true,
}
}, // css预设器配置项
requireModuleExtension: true // 启用 CSS modules for all css / pre-processor files.
},
};