const { defineConfig } = require('@vue/cli-service') const path = require('path') // Node.js的path模块提供了一些用于处理文件路径的小工具 const settings = require('./src/settings.js') const name = settings.title // 页面标题 const port = process.env.port || process.env.npm_config_port || 8080 // dev端口号 function resolve(dir) { return path.join(__dirname, dir) // 连接路径,会正确使用当前系统的路径分隔符,Unix系统是"/",Windows系统是"\" } const webpack = require("webpack"); module.exports = defineConfig({ // If you want to transpile all dependencies: transpileDependencies: true, // If you selectively transpile dependencies: transpileDependencies: ["@kitware/vtk.js"], lintOnSave: false, //关闭语法检查 publicPath: '', outputDir: 'dist',//输出目录 assetsDir: 'static',//编译文件存放目录 // lintOnSave: process.env.NODE_ENV === 'development',//dev环境保存时eslint校验 productionSourceMap: false,//prod环境不启用sourceMap // hot:"only", devServer: { port: port, allowedHosts: 'all', historyApiFallback: true, proxy: { '/api': { // target: 'http://localhost:8081/', // 后端接口地址 target: 'http://192.168.0.131:8187/TransServlet', //target: 'http://192.168.0.131:8087/TransServlet', // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址 secure: false, //接受使用https changeOrigin: true, //允许跨域 ws: false, //使用websocket pathRewrite: { // 路径重写 '^/api': '' } }, '/file': { // target: 'http://192.168.0.15:8081/', // 后端接口地址 target: 'http://192.168.0.43:2201/', secure: false, //接受使用https changeOrigin: true, //允许跨域 ws: false, //使用websocket pathRewrite: { // 路径重写 '^/file': '' } }, '/websokct':{ target: 'http://192.168.0.131:8081/', // target: 'http://192.168.0.43:8081/', // target: 'https://www.gzchain.org.cn/managersvc/', //后端接口地址 secure: false, //接受使用https } }, open: false,//不自动打开浏览器 // overlay: { // warnings: false, // errors: true // }, }, configureWebpack: { // 创建别名(在webpack的name字段中提供别名,以便在index.html中插入正确的引用路径) name: name, resolve: { alias: { '@': resolve('src') } } }, chainWebpack(config) { config.plugins.delete('preload') // TODO: need test config.plugins.delete('prefetch') // TODO: need test // 设置 svg-sprite-loader 插件生效文件夹(src/icons) config.module .rule('svg') .exclude.add(resolve('src/icons')) .end() config.module .rule('icons') .test(/\.svg$/) .include.add(resolve('src/icons')) .end() .use('svg-sprite-loader') .loader('svg-sprite-loader') .options({ symbolId: 'icon-[name]' }) .end() // 设置 preserveWhitespace config.module .rule('vue') .use('vue-loader') .loader('vue-loader') .tap(options => { // options.compilerOptions.preserveWhitespace = true return options }) .end() // config.module // .rule('THREE') // .use('imports-loader?THREE=three') // .loader('imports-loader') // .end() // config.module // .rule('OrbitControls”') // .use('exports-loader?THREE.OrbitControls') // .loader('exports-loader') // .end() // webpack的SourceMaps 7种打包编译模式详见 https://webpack.js.org/configuration/devtool/#development config .when(process.env.NODE_ENV === 'development', config => config.devtool('cheap-source-map') // 生成一个没有列信息(column-mappings)的SourceMaps文件,不包含loader的sourcemap(譬如babel的sourcemap) ) config .when(process.env.NODE_ENV !== 'development', config => { config .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ // `runtime` 必须与runtimeChunk名称相同,默认值为`runtime` 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', // 将elementUI拆分为一个包 priority: 20, // weight必须大于libs和app,否则将打包成libs或app test: /[\\/]node_modules[\\/]_?element-plus(.*)/ // 为了适应cnpm }, commons: { name: 'chunk-commons', test: resolve('src/components'), // 可以自定义规则 minChunks: 3, // 最小公共数 priority: 5, reuseExistingChunk: true } } }) config.optimization.runtimeChunk('single') } ) } })