|
- const ImageminPlugin = require("imagemin-webpack-plugin").default;
- const ImageminMozjpeg = require("imagemin-mozjpeg");
- const ImageminWebpPlugin = require("imagemin-webp-webpack-plugin");
-
- const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
- const CompressionPlugin = require("compression-webpack-plugin");
- const CopyPlugin = require("copy-webpack-plugin");
-
- module.exports = {
- productionSourceMap: false,
- lintOnSave: process.env.NODE_ENV === "development",
- configureWebpack: (config) => {
- const plugins = [
- new ImageminPlugin({
- test: /\.(jpe?g|png|gif|svg)$/i,
- optipng: {
- // imagemin-optipng
- optimizationLevel: 3 // 0~7
- },
- pngquant: null, // imagemin-pngquant
- gifsicle: {
- // imagemin-gifsicle
- optimizationLevel: 1 // 1~3
- },
- svgo: {}, // imagemin-svgo
- jpegtran: null, // imagemin-jpegtran
- plugins: [
- // imagemin-mozjpeg
- ImageminMozjpeg({
- quality: 75
- })
- ]
- })
- ];
-
- if (process.env.NODE_ENV !== "development") {
- plugins.push(
- new ImageminWebpPlugin({
- config: [
- {
- test: /\.(jpe?g)$/,
- options: {
- quality: 75
- }
- },
- {
- test: /\.(png|gif|svg)$/,
- options: {
- quality: 85
- }
- }
- ],
- overrideExtension: false,
- detailedLogs: false,
- silent: false,
- strict: false
- })
- );
-
- plugins.push(
- new CompressionPlugin({
- test: /\.(js|\.html|\.css|\.json)$/,
- algorithm: "gzip",
- threshold: 10240,
- minRatio: 0.8
- })
- );
- }
-
- if (process.env.ANALYZER) {
- plugins.push(
- new BundleAnalyzerPlugin({
- // 可视化分析打包后输出的Bundle体积大小
- analyzerMode: "disabled",
- generateStatsFile: true,
- statsOptions: { source: false }
- })
- );
- }
- config.plugins = [...config.plugins, ...plugins];
- },
- chainWebpack: (config) => {
- if (config.plugins.has("copy")) {
- config.plugin("copy").tap((args) => {
- args[0][0].ignore.push("static/json/*.json");
- return args;
- });
- }
-
- // // 小于10kb的图片资源才进行Base64编码内联,默认是4k
- // config.module
- // .rule("images")
- // .test(/\.(jpe?g|png|gif|svg|webp)(\?.*)?$/)
- // .use("url-loader")
- // .loader("url-loader")
- // .tap((options) => Object.assign(options, { limit: 10240 }));
- },
- css: {
- loaderOptions: {
- scss: {
- prependData: `@import "@/styles/dimens.scss";`
- }
- }
- },
- devServer: {
- // http2: true,
- // https: true,
- // host: "localhost", //前端服务启动后的访问ip,默认为localhost, host和port组成了前端服务启动后的访问入口。
- https: false,
- open: true,
- proxy: {
- "/nuodi": {
- target: "https://lecooai.knowdee.com/sdk/api/v1/dialog/chat", //匹配到要代理的上下文后,将上下文前面的地址替换为此代理地址
- changeOrigin: true, //是否跨域
- pathRewrite: {
- "^/nuodi": "/" //拦截到的上下文重写,这里可以将 kweb 重写为空或者其它值,因为我不需要重写,所以这里这么配置。
- }
- },
- "/srv": {
- target: "https://ai.lecooai.com", //匹配到要代理的上下文后,将上下文前面的地址替换为此代理地址
- changeOrigin: true, //是否跨域
- pathRewrite: {
- "^/srv": "/" //拦截到的上下文重写,这里可以将 kweb 重写为空或者其它值,因为我不需要重写,所以这里这么配置。
- }
- }
- },
- overlay: {
- // warnings: true,
- errors: true
- }
- }
- };
|