代码拉取完成,页面将自动刷新
"use strict";
const path = require("path");
const { title, abbreviation, devPort } = require("./src/config/settings");
const pkg = require("./package.json");
const Webpack = require("webpack");
const WebpackBar = require("webpackbar");
const FileManagerPlugin = require("filemanager-webpack-plugin");
const date = require("dayjs")().format("YYYY_M_D");
const time = require("dayjs")().format("YYYY-M-D HH:mm:ss");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = ["html", "js", "css", "svg"];
function resolve(dir) {
return path.join(__dirname, dir);
}
function mockServer() {
if (process.env.NODE_ENV === "development") {
const mockServer = require("./mock/mock-server.js");
return mockServer;
} else {
return "";
}
}
const name = title || "vue-admin-beautiful";
module.exports = {
publicPath: "",
assetsDir: "static",
outputDir: "dist",
lintOnSave: false, // 暂时关闭语法检查
transpileDependencies: ["vue-echarts", "resize-detector"],
devServer: {
hot: true,
port: devPort,
open: true,
noInfo: false,
overlay: {
warnings: true,
errors: true,
},
after: mockServer(),
proxy: {
'/proxy': {
timeout: 30000,
target: 'http://192.168.0.111:8080', // 你请求的第三方接口
// target: 'https://api.melson.vip', // 你请求的第三方接口
changeOrigin: true, // 在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
pathRewrite: { // 路径重写,
'^/proxy': '' // 替换target中的请求地址,也就是说以后你在请求http://api.douban.com/v2/XXXXX这个地址的时候直接写成/api即可。
}
},
'/imserver': {
target: 'ws://192.168.0.111:8080',
ws: true,
secure: false,
// logLevel: 'debug',
},
}
},
configureWebpack(config) {
return {
name: name,
resolve: {
alias: {
"@": resolve("src"),
"^": resolve("src/components"),
"~": resolve("node_modules")
},
},
plugins: [
new Webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery",
echarts: "echarts",
"window.echarts": "echarts",
maptalks: "maptalks",
"window.maptalks": "maptalks",
}),
new Webpack.DefinePlugin({
"process.env.VUE_APP_UPDATE_TIME": "'" + time + "'",
}),
new WebpackBar({
name: `\u0076\u0075\u0065\u002d\u0061\u0064\u006d\u0069\u006e\u002d\u0062\u0065\u0061\u0075\u0074\u0069\u0066\u0075\u006c`,
}),
],
};
},
chainWebpack(config) {
config.plugins.delete("preload");
config.plugins.delete("prefetch");
config.resolve.symlinks(true);
config.module
.rule("svg")
.exclude.add(resolve("src/remixIcon"))
.add(resolve("src/colorfulIcon"))
.end();
config.module
.rule("remixIcon")
.test(/\.svg$/)
.include.add(resolve("src/remixIcon"))
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({ symbolId: "remix-icon-[name]" })
.end();
config.module
.rule("colorfulIcon")
.test(/\.svg$/)
.include.add(resolve("src/colorfulIcon"))
.end()
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({ symbolId: "colorful-icon-[name]" })
.end();
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap((options) => {
options.compilerOptions.preserveWhitespace = true;
return options;
})
.end();
config.when(process.env.NODE_ENV === "development", (config) => {
config.devtool("cheap-module-eval-source-map");
});
config.when(process.env.NODE_ENV !== "development", (config) => {
config.performance.set("hints", false);
config.devtool("none");
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",
priority: 20,
test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
},
commons: {
name: "chunk-commons",
test: resolve("src/components"),
minChunks: 3,
priority: 5,
reuseExistingChunk: true,
},
},
});
config.optimization.runtimeChunk("single");
config
.plugin("banner")
.use(Webpack.BannerPlugin, [
` \u57fa\u4e8e\u0076\u0075\u0065\u002d\u0061\u0064\u006d\u0069\u006e\u002d\u0062\u0065\u0061\u0075\u0074\u0069\u0066\u0075\u006c\u6784\u5efa \n \u0063\u006f\u0070\u0079\u0072\u0069\u0067\u0068\u0074\u003a\u0020\u0063\u0068\u0075\u007a\u0068\u0069\u0078\u0069\u006e\u0020\u0031\u0032\u0030\u0034\u0035\u0030\u0035\u0030\u0035\u0036\u0040\u0071\u0071\u002e\u0063\u006f\u006d \n \u0074\u0069\u006d\u0065\u003a ${time}`,
])
.end();
});
config
.plugin("compression")
.use(CompressionWebpackPlugin, [
{
filename: "[path].gz[query]",
algorithm: "gzip",
test: new RegExp("\\.(" + productionGzipExtensions.join("|") + ")$"),
threshold: 8192,
minRatio: 0.8,
},
])
.end();
config.when(process.env.NODE_ENV === "production", (config) => {
config
.plugin("fileManager")
.use(FileManagerPlugin, [
{
onEnd: {
delete: ["./dist/video", "./dist/data"],
archive: [
{
source: "./dist",
destination: `./dist/${abbreviation}_dist_${date}.7z`,
},
],
},
},
])
.end();
});
},
runtimeCompiler: true,
productionSourceMap: false,
css: {
requireModuleExtension: true,
sourceMap: true,
loaderOptions: {
scss: {
/*sass-loader 8.0语法 */
prependData: '@import "~@/styles/variables.scss";',
/*sass-loader 9.0写法,感谢github用户 shaonialife*/
// additionalData(content, loaderContext) {
// const { resourcePath, rootContext } = loaderContext;
// const relativePath = path.relative(rootContext, resourcePath);
// if (
// relativePath.replace(/\\/g, "/") !== "src/styles/variables.scss"
// ) {
// return '@import "~@/styles/variables.scss";' + content;
// }
// return content;
// },
},
},
},
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。