"use strict"; const path = require("path"); const defaultSettings = require("./src/settings.js"); const dayjs = require("dayjs"); function resolve(dir) { return path.join(__dirname, dir); } const name = defaultSettings.title; // 标题 const host = "localhost"; // 默认以本机ip启动 const port = process.env.port || process.env.VUE_APP_PORT || 8080; // 端口 // vue.config.js 配置说明 //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions // 这里只列一部分,具体配置参考文档 module.exports = { // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。 publicPath: "", // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist) outputDir: "dist", // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下) assetsDir: "static", // 是否开启eslint保存检测,有效值:ture | false | 'error' lintOnSave: process.env.NODE_ENV === "development", // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。 productionSourceMap: false, // webpack-dev-server 相关配置 devServer: { host, port, open: true, proxy: { [process.env.VUE_APP_API_ROOT]: { target: `${process.env.VUE_APP_API}${process.env.VUE_APP_API_ROOT}`, changeOrigin: true, pathRewrite: { ["^" + process.env.VUE_APP_API_ROOT]: "", }, }, "/obpm": { target: "https://v5qy.te.baibaodun.com.cn", changeOrigin: true, pathRewrite: { ["^" + process.env.VUE_APP_API_ROOT]: "", }, }, [process.env.VUE_APP_BCX_API_URL]: { // target: "https://identify.qiye.baibaodun.com.cn:14433", target: process.env.VUE_APP_BCX_IDENTITY_API, changeOrigin: true, secure: true, pathRewrite: { ["^" + process.env.VUE_APP_BCX_API_URL]: "", }, }, [process.env.VUE_APP_IM_AUDIO_API]: { target: "https://cos.ap-shanghai.myqcloud.com", changeOrigin: true, secure: true, pathRewrite: { ["^" + process.env.VUE_APP_IM_AUDIO_API]: "", }, }, [process.env.VUE_APP_UPLOAD_API]: { target: "https://jsonplaceholder.typicode.com", changeOrigin: true, secure: true, pathRewrite: { ["^" + process.env.VUE_APP_IM_AUDIO_API]: "", }, }, [process.env.VUE_APP_GWSD_API_ROOT]: { // target: "http://gis.baibaodun.cn:50001/gis", target: "http://49.4.21.141:50001/gis", changeOrigin: true, secure: true, pathRewrite: { ["^" + process.env.VUE_APP_GWSD_API_ROOT]: "", }, }, }, headers: { // 重点1: 允许跨域访问子应用页面 "Access-Control-Allow-Origin": "*", }, historyApiFallback: true, disableHostCheck: true, }, css: { loaderOptions: { sass: { implementation: require("sass"), // additionalData: "", }, }, }, configureWebpack: { name: name, resolve: { extensions: [".js", ".vue", ".json"], alias: { vue$: "vue/dist/vue.esm.js", "@": resolve("src"), views: path.resolve(__dirname, "./src/views"), "@img": path.resolve(__dirname, "./src/img"), "@components": path.resolve(__dirname, "./src/components"), "@styles": path.resolve(__dirname, "./src/styles"), "@assets": path.resolve(__dirname, "./src/assets"), }, }, plugins: [], devtool: "source map" }, chainWebpack(config) { config.plugins.delete("preload"); // TODO: need test config.plugins.delete("prefetch"); // TODO: need test config.plugin("html").tap((args) => { if (process.env.NODE_ENV === "production") { args[0].minify.removeComments = false; } return args; }); // 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.plugin("html").tap((args) => { args[0].title = name; return args; }); config.plugin("define").tap((args) => { args[0]["process.env"].PACKAGE_VERSION = JSON.stringify( require("./package.json").version + "." + dayjs().format("YYYYMMDDHHmmss") ); return args; }); config.when(process.env.NODE_ENV !== "development", (config) => { config .plugin("ScriptExtHtmlWebpackPlugin") .after("html") .use("script-ext-html-webpack-plugin", [ { // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/, }, ]) .end(); config.optimization.splitChunks({ chunks: "all", cacheGroups: { libs: { name: "chunk-libs", test: /[\\/]node_modules[\\/]/, priority: 10, chunks: "initial", // only package third parties that are initially dependent }, elementUI: { name: "chunk-elementUI", // split elementUI into a single package priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm }, commons: { name: "chunk-commons", test: resolve("src/components"), // can customize your rules minChunks: 3, // minimum common number priority: 5, reuseExistingChunk: true, }, }, }); config.optimization.runtimeChunk("single"); }); config.module .rule("vue") .use("vue-loader") .loader("vue-loader") .tap((options) => { options.compilerOptions.directives = { html(node, directiveMeta) { (node.props || (node.props = [])).push({ name: "innerHTML", value: `xss(_s(${directiveMeta.value}), xssOptions())`, }); }, }; return options; }); }, transpileDependencies: ["screenfull"], };