const path = require("path"); const webpack = require("webpack"); // 根据环境判断使用哪份配置 // const cfg = process.env.NODE_ENV === 'production' ? configs.build.env : configs.dev.env; const production = process.env.NODE_ENV === "production"; module.exports = { publicPath: "./", //基本路径 outputDir: "dist", //构建时的输出目录 assetsDir: "static", //放置静态资源的目录 indexPath: "index.html", //html 的输出路径 filenameHashing: true, //文件名哈希值 lintOnSave: false, //是否在保存的时候使用 `eslint-loader` 进行检查。 //组件是如何被渲染到页面中的? (ast:抽象语法树;vDom:虚拟DOM) //template ---> ast ---> render ---> vDom ---> 真实的Dom ---> 页面 //runtime-only:将template在打包的时候,就已经编译为render函数 //runtime-compiler:在运行的时候才去编译template runtimeCompiler: false, transpileDependencies: [], //babel-loader 默认会跳过 node_modules 依赖。 productionSourceMap: false, //是否为生产环境构建生成 source map? //调整内部的 webpack 配置 configureWebpack: { plugins: [], }, chainWebpack: (config) => { config.resolve.alias .set("vue$", "vue/dist/vue.esm.js") .set("@", path.resolve("src")) .set("@assets", path.resolve("src/assets")) .set("@components", path.resolve("src/components")) .set("@views", path.resolve("src/views")) .set("@router", path.resolve("src/router")) .set("@store", path.resolve("src/store")); // config.resolve = { // // 配置解析别名 // extensions: [".js", ".json", ".vue"], //在import这些拓展名的文件时,可以省略拓展名 // alias: { // "@": path.resolve(__dirname, "./src"), // public: path.resolve(__dirname, "./public"), // components: path.resolve(__dirname, "./src/components"), // api: path.resolve(__dirname, "./src/api"), // views: path.resolve(__dirname, "./src/views"), // }, // }; if (process.env.NODE_ENV === "production") { config.plugin("chunkPlugin").use(webpack.optimize.LimitChunkCountPlugin, [ { maxChunks: 6, // 必须大于或等于 1 minChunkSize: 10000, }, ]); } if (!production) { //源码查看配置 config.output.devtoolModuleFilenameTemplate = (info) => { const resPath = info.resourcePath; if ( (/\.vue$/.test(resPath) && !/type=script/.test(info.identifier)) || /node_modules/.test(resPath) ) { return `webpack:///${resPath}?${info.hash}`; } return `webpack:///${resPath.replace("./src", "my-code/src")}`; }; } }, // devServer: { // port: 7000, // open: true, // hot: true, // }, // 配置 webpack-dev-server 行为。 devServer: { open: true, //编译后默认打开浏览器 // host: '192.168.30.17', //域名 port: 7500, // 端口 https: false, //是否https //显示警告和错误 // overlay: { // warnings: false, // errors: true // }, // proxy: 'http://192.168.2.31:8060', // proxy: 'http://49.4.123.194', proxy: { "/v3": { // target: 'http://49.4.123.194:37080', target: "https://v5qy.te.baibaodun.com.cn", // target: "https://v5qy.baibaodun.cn", logLevel: "debug", changeOrigin: true, //是否跨域 ws: false, //是否支持websocket secure: false, //如果是https接口,需要配置这个参数 pathRewrite: { "^/v3": "/v3", }, }, "/obpm": { // target: 'http://49.4.123.194:37080', target: "https://v5qy.te.baibaodun.com.cn", // target: "https://v5qy.baibaodun.cn", logLevel: "debug", changeOrigin: true, //是否跨域 ws: false, //是否支持websocket secure: false, //如果是https接口,需要配置这个参数 pathRewrite: { "^/obpm": "/obpm", }, }, ComServiceApi: { target: "http://attends.test.baibaodun.cn", logLevel: "debug", changeOrigin: true, //是否跨域 ws: false, //是否支持websocket secure: false, //如果是https接口,需要配置这个参数 pathRewrite: { "^/ComServiceApi": "", }, }, }, }, // 第三方插件配置 // pluginOptions: { // // ... // }, };