You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
4.6 KiB
169 lines
4.6 KiB
'use strict'
|
|
const path = require('path')
|
|
const fs = require('fs')
|
|
|
|
function resolve(dir) {
|
|
return path.join(__dirname, dir)
|
|
}
|
|
|
|
// 离线瓦片目录:放在 public 外避免构建时复制导致 EMFILE(too many open files)
|
|
const tilesDir = path.join(__dirname, 'tiles')
|
|
const tilesInPublic = path.join(__dirname, 'public', 'tiles')
|
|
|
|
const CompressionPlugin = require('compression-webpack-plugin')
|
|
// 引入 CopyWebpackPlugin 用于复制 Cesium 静态资源
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const name = process.env.VUE_APP_TITLE || '若依管理系统' // 网页标题
|
|
const baseUrl = 'http://127.0.0.1:8080' // 后端接口
|
|
const port = process.env.port || process.env.npm_config_port || 80 // 端口
|
|
|
|
// 定义 Cesium 源码路径
|
|
const cesiumSource = 'node_modules/cesium/Build/Cesium'
|
|
|
|
module.exports = {
|
|
// 部署生产环境和开发环境下的URL。
|
|
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
|
|
outputDir: 'dist',
|
|
assetsDir: 'static',
|
|
productionSourceMap: false,
|
|
|
|
// 核心修改:让 Babel 编译 Cesium 和相关依赖,解决语法报错
|
|
transpileDependencies: [
|
|
'quill',
|
|
'cesium',
|
|
'@cesium/engine',
|
|
'@cesium/widgets',
|
|
'@zip.js',
|
|
'@spz-loader'
|
|
],
|
|
|
|
devServer: {
|
|
host: '0.0.0.0',
|
|
port: port,
|
|
open: true,
|
|
// 从 public 外提供 /tiles,避免 2 万+ 瓦片参与 public 复制触发 EMFILE
|
|
before(app) {
|
|
const express = require('express')
|
|
const serveAt = fs.existsSync(tilesDir) ? tilesDir : tilesInPublic
|
|
app.use('/tiles', express.static(serveAt))
|
|
},
|
|
proxy: {
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
target: baseUrl,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
['^' + process.env.VUE_APP_BASE_API]: ''
|
|
}
|
|
},
|
|
'^/v3/api-docs/(.*)': {
|
|
target: baseUrl,
|
|
changeOrigin: true
|
|
}
|
|
},
|
|
disableHostCheck: true
|
|
},
|
|
|
|
css: {
|
|
loaderOptions: {
|
|
sass: {
|
|
sassOptions: { outputStyle: "expanded" }
|
|
}
|
|
}
|
|
},
|
|
|
|
configureWebpack: {
|
|
name: name,
|
|
resolve: {
|
|
alias: {
|
|
'@': resolve('src')
|
|
}
|
|
},
|
|
plugins: [
|
|
// 核心修改:复制 Cesium 静态资源到 public/cesium 目录下
|
|
new CopyWebpackPlugin([
|
|
{ from: path.join(cesiumSource, 'Workers'), to: 'cesium/Workers' },
|
|
{ from: path.join(cesiumSource, 'Assets'), to: 'cesium/Assets' },
|
|
{ from: path.join(cesiumSource, 'Widgets'), to: 'cesium/Widgets' },
|
|
{ from: path.join(cesiumSource, 'ThirdParty'), to: 'cesium/ThirdParty' }
|
|
]),
|
|
|
|
// gzip压缩
|
|
new CompressionPlugin({
|
|
cache: false,
|
|
test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i,
|
|
filename: '[path][base].gz[query]',
|
|
algorithm: 'gzip',
|
|
minRatio: 0.8,
|
|
deleteOriginalAssets: false
|
|
})
|
|
]
|
|
},
|
|
|
|
chainWebpack(config) {
|
|
config.plugins.delete('preload')
|
|
config.plugins.delete('prefetch')
|
|
|
|
// 核心修改:添加 import.meta 加载器支持 (解决 Cesium 1.97+ 报错)
|
|
config.module
|
|
.rule('import-meta')
|
|
.test(/\.js$/)
|
|
.include.add(/node_modules/)
|
|
.end()
|
|
.use('import-meta-loader')
|
|
.loader('@open-wc/webpack-import-meta-loader')
|
|
.end();
|
|
|
|
// set svg-sprite-loader
|
|
config.module
|
|
.rule('svg')
|
|
.exclude.add(resolve('src/assets/icons'))
|
|
.end()
|
|
config.module
|
|
.rule('icons')
|
|
.test(/\.svg$/)
|
|
.include.add(resolve('src/assets/icons'))
|
|
.end()
|
|
.use('svg-sprite-loader')
|
|
.loader('svg-sprite-loader')
|
|
.options({
|
|
symbolId: 'icon-[name]'
|
|
})
|
|
.end()
|
|
|
|
config.when(process.env.NODE_ENV !== 'development', config => {
|
|
config
|
|
.plugin('ScriptExtHtmlWebpackPlugin')
|
|
.after('html')
|
|
.use('script-ext-html-webpack-plugin', [{
|
|
inline: /runtime\..*\.js$/
|
|
}])
|
|
.end()
|
|
|
|
config.optimization.splitChunks({
|
|
chunks: 'all',
|
|
cacheGroups: {
|
|
libs: {
|
|
name: 'chunk-libs',
|
|
test: /[\\/]node_modules[\\/]/,
|
|
priority: 10,
|
|
chunks: 'initial'
|
|
},
|
|
elementUI: {
|
|
name: 'chunk-elementUI',
|
|
test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
|
|
priority: 20
|
|
},
|
|
commons: {
|
|
name: 'chunk-commons',
|
|
test: resolve('src/components'),
|
|
minChunks: 3,
|
|
priority: 5,
|
|
reuseExistingChunk: true
|
|
}
|
|
}
|
|
})
|
|
config.optimization.runtimeChunk('single')
|
|
})
|
|
}
|
|
}
|
|
|