zhgdyun/vue.config.js

173 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-09-27 13:40:51 +08:00
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
2024-09-30 17:30:16 +08:00
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
2022-06-08 14:51:11 +08:00
// 代码压缩
const TerserPlugin = require("terser-webpack-plugin");
2022-11-10 09:18:38 +08:00
function addStyleResource(rule) {
rule
.use("style-resource")
.loader("style-resources-loader")
2022-06-08 14:51:11 +08:00
.options({
patterns: [
2022-11-10 09:18:38 +08:00
path.resolve(__dirname, "src/assets/style/var.less"), //全局引入的less文件
path.resolve(__dirname, "src/assets/style/longguang.less"), //全局引入的less文件--龙光地产
2022-06-08 14:51:11 +08:00
],
2022-11-10 09:18:38 +08:00
});
2022-06-08 14:51:11 +08:00
}
module.exports = {
// publicPath: process.env.NODE_ENV === "production" ? "/jxjgd" : "/jxjgd",//金林湾配置
2022-06-08 14:51:11 +08:00
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
2022-11-10 09:18:38 +08:00
devServer: {
2022-10-26 10:56:31 +08:00
// host: 'localhost',
2022-11-10 09:18:38 +08:00
proxy: {
"/china": {
2022-07-22 15:53:09 +08:00
target: "http://122.112.239.62:9000",
2022-11-10 09:18:38 +08:00
changeOrigin: true,
pathRewrite: {
"^/china": "", //重写路径
},
2024-09-30 17:30:16 +08:00
'/img_w/wmts': {
target: 'https://t5.tianditu.gov.cn',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/img_w/wmts': '/img_w/wmts'
}
2024-10-17 18:04:47 +08:00
},
}
2022-11-10 09:18:38 +08:00
},
2022-07-22 15:53:09 +08:00
},
2022-11-10 09:18:38 +08:00
pages: {
2022-06-08 14:51:11 +08:00
index: {
entry: "./src/pages/index/index.js",
template: "./src/pages/index/index.html",
filename: "index.html",
2022-11-10 09:18:38 +08:00
title: "机械设备管理平台",
2022-06-08 14:51:11 +08:00
},
equipmentCenter: {
entry: "./src/pages/equipmentCenter/equipmentCenter.js",
template: "./src/pages/equipmentCenter/equipmentCenter.html",
filename: "equipmentCenter.html",
2022-11-10 09:18:38 +08:00
title: "设备中台",
2022-06-08 14:51:11 +08:00
},
2022-11-10 09:18:38 +08:00
},
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: [],
2022-06-08 14:51:11 +08:00
},
2022-11-10 09:18:38 +08:00
},
2024-09-27 13:40:51 +08:00
2022-11-10 09:18:38 +08:00
productionSourceMap: false,
2024-09-27 13:40:51 +08:00
2024-09-30 17:30:16 +08:00
configureWebpack: config => {
config.module.rules.push({
test: /\.js$/,
include: path.resolve(__dirname, 'packages'),
use: [
{
loader: 'babel-loader',
options: {
// Babel options here
}
}
]
});
config.optimization = {
2022-11-10 09:18:38 +08:00
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ["console.log"], // 移除console
2022-06-08 14:51:11 +08:00
},
2022-11-10 09:18:38 +08:00
},
}),
],
2024-09-30 17:30:16 +08:00
};
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);
2022-11-10 09:18:38 +08:00
},
// configureWebpack: (config) => {
// Object.assign(config, {
// // 开发生产共同配置
// resolve: {
// alias: {
// '@': path.resolve(__dirname, './src'),
// '@c': path.resolve(__dirname, './src/components'),
// '@p': path.resolve(__dirname, './src/assets/j')
// } // 别名配置
// }
// })
// }
2024-09-30 17:30:16 +08:00
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.
},
2024-09-27 13:40:51 +08:00
2022-11-10 09:18:38 +08:00
};