@umijs/bundler-webpack 4.0.1 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,9 +14,6 @@ async function addAssetRules(opts) {
14
14
  dataUrlCondition: {
15
15
  maxSize: inlineLimit,
16
16
  },
17
- })
18
- .generator({
19
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
20
17
  });
21
18
  rule
22
19
  .oneOf('image')
@@ -26,9 +23,6 @@ async function addAssetRules(opts) {
26
23
  dataUrlCondition: {
27
24
  maxSize: inlineLimit,
28
25
  },
29
- })
30
- .generator({
31
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
32
26
  });
33
27
  const fallback = rule
34
28
  .oneOf('fallback')
@@ -40,11 +34,6 @@ async function addAssetRules(opts) {
40
34
  if (userConfig.mdx) {
41
35
  fallback.add(/\.mdx?$/);
42
36
  }
43
- fallback
44
- .end()
45
- .type('asset/resource')
46
- .generator({
47
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
48
- });
37
+ fallback.end().type('asset/resource');
49
38
  }
50
39
  exports.addAssetRules = addAssetRules;
@@ -78,7 +78,8 @@ async function getConfig(opts) {
78
78
  .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
79
79
  .chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`)
80
80
  .publicPath(userConfig.publicPath || 'auto')
81
- .pathinfo(isDev || disableCompress);
81
+ .pathinfo(isDev || disableCompress)
82
+ .set('assetModuleFilename', `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`);
82
83
  // resolve
83
84
  // prettier-ignore
84
85
  config.resolve
@@ -4,23 +4,20 @@ exports.addCopyPlugin = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  async function addCopyPlugin(opts) {
7
+ var _a;
7
8
  const { config, userConfig, cwd } = opts;
8
9
  const copyPatterns = [
9
10
  (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
10
11
  from: (0, path_1.join)(cwd, 'public'),
11
12
  },
12
13
  ...(userConfig.copy
13
- ? userConfig.copy.map((item) => {
14
- if (typeof item === 'string') {
15
- return {
16
- from: (0, path_1.join)(cwd, item),
17
- to: item,
18
- };
14
+ ? (_a = userConfig.copy) === null || _a === void 0 ? void 0 : _a.map((pattern) => {
15
+ if (typeof pattern === 'string') {
16
+ return (0, path_1.resolve)(cwd, pattern);
19
17
  }
20
18
  return {
21
- // 相对于 process.cwd,所以这里需要使用绝对路径
22
- from: (0, path_1.join)(cwd, item.from),
23
- to: item.to,
19
+ from: (0, path_1.resolve)(cwd, pattern.from),
20
+ to: (0, path_1.resolve)(cwd, pattern.to),
24
21
  };
25
22
  })
26
23
  : []),
@@ -65,7 +65,15 @@ async function addCSSRules(opts) {
65
65
  .options({
66
66
  importLoaders: 1,
67
67
  esModule: true,
68
- url: true,
68
+ url: {
69
+ filter: (url) => {
70
+ // Don't parse absolute URLs
71
+ // ref: https://github.com/webpack-contrib/css-loader#url
72
+ if (url.startsWith('/'))
73
+ return false;
74
+ return true;
75
+ },
76
+ },
69
77
  import: true,
70
78
  ...(isCSSModules
71
79
  ? {
@@ -35,20 +35,14 @@ async function addSVGRules(opts) {
35
35
  .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
36
36
  .end();
37
37
  }
38
- if (svgo === false) {
38
+ if (svgo !== false) {
39
39
  const svgRule = config.module.rule('svg');
40
40
  svgRule
41
41
  .test(/\.svg$/)
42
- .use('url-loader')
43
- .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
44
- return;
42
+ .use('svgo-loader')
43
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
44
+ .options({ configFile: false, ...svgo })
45
+ .end();
45
46
  }
46
- const svgRule = config.module.rule('svg');
47
- svgRule
48
- .test(/\.svg$/)
49
- .use('svgo-loader')
50
- .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
51
- .options({ configFile: false, ...svgo })
52
- .end();
53
47
  }
54
48
  exports.addSVGRules = addSVGRules;
package/dist/dev.d.ts CHANGED
@@ -19,6 +19,9 @@ declare type IOpts = {
19
19
  rootDir?: string;
20
20
  config: IConfig;
21
21
  entry: Record<string, string>;
22
+ mfsuStrategy?: 'eager' | 'normal';
23
+ mfsuInclude?: string[];
24
+ srcCodeCache?: any;
22
25
  } & Pick<IConfigOpts, 'cache'>;
23
26
  export declare function stripUndefined(obj: any): any;
24
27
  export declare function dev(opts: IOpts): Promise<void>;
package/dist/dev.js CHANGED
@@ -32,6 +32,9 @@ async function dev(opts) {
32
32
  utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
33
33
  }
34
34
  mfsu = new mfsu_1.MFSU({
35
+ strategy: opts.mfsuStrategy,
36
+ include: opts.mfsuInclude || [],
37
+ srcCodeCache: opts.srcCodeCache,
35
38
  implementor: webpack_1.default,
36
39
  buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
37
40
  depBuildConfig: {
@@ -75,7 +78,7 @@ async function dev(opts) {
75
78
  extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
76
79
  chainWebpack: opts.chainWebpack,
77
80
  modifyWebpackConfig: opts.modifyWebpackConfig,
78
- hmr: true,
81
+ hmr: process.env.HMR !== 'none',
79
82
  analyze: process.env.ANALYZE,
80
83
  cache: opts.cache,
81
84
  });
@@ -109,7 +112,7 @@ async function dev(opts) {
109
112
  typeof webpackConfig.cache === 'object' &&
110
113
  webpackConfig.cache.type === 'filesystem') {
111
114
  const webpackCachePath = (0, path_1.join)(webpackConfig.cache.cacheDirectory, `default-development`, 'index.pack');
112
- const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.depInfo.cacheFilePath);
115
+ const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.getCacheFilePath());
113
116
  const webpackCacheExists = (0, fs_1.existsSync)(webpackCachePath);
114
117
  if (webpackCacheExists && !mfsuCacheExists) {
115
118
  utils_1.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
package/dist/schema.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- /// <reference types="hapi__joi" />
2
- import type { Root } from '@hapi/joi';
1
+ import type { Root } from '@umijs/utils/compiled/@hapi/joi';
3
2
  export declare function getSchemas(): Record<string, (Joi: Root) => any>;
package/dist/schema.js CHANGED
@@ -74,8 +74,10 @@ function getSchemas() {
74
74
  cacheDirectory: Joi.string(),
75
75
  chainWebpack: Joi.function(),
76
76
  esbuild: Joi.boolean(),
77
+ include: Joi.array().items(Joi.string()),
77
78
  mfName: Joi.string(),
78
79
  runtimePublicPath: Joi.boolean(),
80
+ strategy: Joi.string().valid('eager', 'normal').default('normal'),
79
81
  }), Joi.boolean()),
80
82
  outputPath: (Joi) => Joi.string(),
81
83
  postcssLoader: (Joi) => Joi.object(),
@@ -138,10 +138,11 @@ async function createServer(opts) {
138
138
  app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
139
139
  ...proxy[key],
140
140
  // Add x-real-url in response header
141
- onProxyRes(proxyRes, req) {
142
- var _a;
141
+ onProxyRes(proxyRes, req, res) {
142
+ var _a, _b;
143
143
  proxyRes.headers['x-real-url'] =
144
144
  ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
145
+ (_b = proxyConfig.onProxyRes) === null || _b === void 0 ? void 0 : _b.call(proxyConfig, proxyRes, req, res);
145
146
  },
146
147
  }));
147
148
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.1",
3
+ "version": "4.0.4",
4
4
  "description": "@umijs/bundler-webpack",
5
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
6
- "bugs": "https://github.com/umijs/umi-next/issues",
5
+ "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
+ "bugs": "https://github.com/umijs/umi/issues",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/umijs/umi-next"
9
+ "url": "https://github.com/umijs/umi"
10
10
  },
11
11
  "license": "MIT",
12
12
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "build": "pnpm tsc",
25
25
  "build:client": "pnpm tsc --project ./tsconfig.client.json",
26
26
  "build:deps": "umi-scripts bundleDeps",
27
- "dev": "pnpm build -- --watch",
27
+ "dev": "pnpm build --watch",
28
28
  "generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs",
29
29
  "test": "umi-scripts jest-turbo"
30
30
  },
@@ -35,10 +35,10 @@
35
35
  "@svgr/plugin-jsx": "^6.2.1",
36
36
  "@svgr/plugin-svgo": "^6.2.0",
37
37
  "@types/hapi__joi": "17.1.8",
38
- "@umijs/babel-preset-umi": "4.0.1",
39
- "@umijs/bundler-utils": "4.0.1",
40
- "@umijs/mfsu": "4.0.1",
41
- "@umijs/utils": "4.0.1",
38
+ "@umijs/babel-preset-umi": "4.0.4",
39
+ "@umijs/bundler-utils": "4.0.4",
40
+ "@umijs/mfsu": "4.0.4",
41
+ "@umijs/utils": "4.0.4",
42
42
  "cors": "^2.8.5",
43
43
  "css-loader": "6.7.1",
44
44
  "es5-imcompatible-versions": "^0.1.73",