| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- const path = require('path');
- module.exports = {
- webpack: {
- configure: (webpackConfig, { env }) => {
- // 设置 publicPath
- // webpackConfig.output.publicPath = 'http://192.168.1.4:8081/';
- // These SVGs are consumed as URLs. Bypass SVGR so Babel does not turn large
- // flag/sprite sources into unnecessary React components first.
- const oneOf = webpackConfig.module.rules.find(rule => Array.isArray(rule.oneOf))?.oneOf;
- const svgRuleIndex = oneOf?.findIndex(rule => rule.test?.test?.("icon.svg"));
- if (svgRuleIndex >= 0) {
- oneOf.splice(svgRuleIndex, 0, {
- test: /[\\/]assets[\\/](?:i18n[\\/][^\\/]+|symbol(?:-defs|-mobile))\.svg$/i,
- type: "asset/resource",
- });
- }
- // CRA development builds use a fixed "static/js/bundle.js" filename, so
- // splitting initial chunks there makes multiple chunks target the same file.
- if (env === "production") {
- const initialChunkMaxSize = 1000000;
- const currentCacheGroups = webpackConfig.optimization.splitChunks?.cacheGroups || {};
- webpackConfig.optimization.splitChunks = {
- ...webpackConfig.optimization.splitChunks,
- cacheGroups: {
- ...currentCacheGroups,
- initialVendors: {
- test: /[\\/]node_modules[\\/]/,
- chunks: "initial",
- enforce: true,
- maxSize: initialChunkMaxSize,
- minSize: 0,
- priority: 30,
- reuseExistingChunk: true,
- },
- initialApp: {
- test: module => module.resource?.startsWith(path.resolve(__dirname, "src")),
- chunks: "initial",
- enforce: true,
- maxSize: initialChunkMaxSize,
- minSize: 0,
- priority: 20,
- reuseExistingChunk: true,
- },
- },
- };
- }
- // 返回修改后的配置
- return webpackConfig;
- },
- alias: {
- '@components': path.resolve(__dirname, 'src/components'),
- '@ui': path.resolve(__dirname, 'src/ui'),
- '@pages': path.resolve(__dirname, 'src/pages'),
- '@assets': path.resolve(__dirname, 'src/assets'),
- '@styles': path.resolve(__dirname, 'src/styles'),
- '@db': path.resolve(__dirname, 'src/db'),
- '@hooks': path.resolve(__dirname, 'src/hooks'),
- '@layout': path.resolve(__dirname, 'src/layout'),
- '@fonts': path.resolve(__dirname, 'src/fonts'),
- '@utils': path.resolve(__dirname, 'src/utils'),
- '@widgets': path.resolve(__dirname, 'src/widgets'),
- '@contexts': path.resolve(__dirname, 'src/contexts'),
- '@constants': path.resolve(__dirname, 'src/constants'),
- '@features': path.resolve(__dirname, 'src/features'),
- '@api':path.resolve(__dirname,'src/api'),
- },
- }
- };
|