@umijs/bundler-webpack 4.0.0-canary.20220624.1 → 4.0.0-canary.20220707.1

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,27 @@ 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'),
12
+ // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
13
+ // Set minimized so terser will not do minimize
14
+ info: { minimized: true },
11
15
  },
12
16
  ...(userConfig.copy
13
- ? userConfig.copy.map((item) => {
14
- if (typeof item === 'string') {
17
+ ? (_a = userConfig.copy) === null || _a === void 0 ? void 0 : _a.map((pattern) => {
18
+ if (typeof pattern === 'string') {
15
19
  return {
16
- from: (0, path_1.join)(cwd, item),
17
- to: item,
20
+ from: (0, path_1.resolve)(cwd, pattern),
21
+ info: { minimized: true },
18
22
  };
19
23
  }
20
24
  return {
21
- // 相对于 process.cwd,所以这里需要使用绝对路径
22
- from: (0, path_1.join)(cwd, item.from),
23
- to: item.to,
25
+ from: (0, path_1.resolve)(cwd, pattern.from),
26
+ to: (0, path_1.resolve)(cwd, pattern.to),
27
+ info: { minimized: true },
24
28
  };
25
29
  })
26
30
  : []),
@@ -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/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as parcelCSS from '@parcel/css';
2
1
  import type webpack from '../compiled/webpack';
3
2
  import './requireHook';
4
3
  export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
@@ -7,5 +6,4 @@ export * from './build';
7
6
  export * from './config/config';
8
7
  export * from './dev';
9
8
  export * from './schema';
10
- export { parcelCSS };
11
9
  export { webpack };
package/dist/index.js CHANGED
@@ -10,25 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
15
  };
28
16
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.parcelCSS = void 0;
30
- const parcelCSS = __importStar(require("@parcel/css"));
31
- exports.parcelCSS = parcelCSS;
32
17
  require("./requireHook");
33
18
  __exportStar(require("./build"), exports);
34
19
  __exportStar(require("./config/config"), exports);
@@ -0,0 +1,2 @@
1
+ import * as parcelCSS from '@parcel/css';
2
+ export { parcelCSS };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parcelCSS = void 0;
27
+ const parcelCSS = __importStar(require("@parcel/css"));
28
+ exports.parcelCSS = parcelCSS;
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
  }
@@ -187,7 +188,7 @@ async function createServer(opts) {
187
188
  const protocol = userConfig.https ? 'https:' : 'http:';
188
189
  const port = opts.port || 8000;
189
190
  server.listen(port, () => {
190
- const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
191
+ const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : 'localhost';
191
192
  utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
192
193
  });
193
194
  return server;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-canary.20220624.1",
3
+ "version": "4.0.0-canary.20220707.1",
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",
@@ -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.0-canary.20220624.1",
39
- "@umijs/bundler-utils": "4.0.0-canary.20220624.1",
40
- "@umijs/mfsu": "4.0.0-canary.20220624.1",
41
- "@umijs/utils": "4.0.0-canary.20220624.1",
38
+ "@umijs/babel-preset-umi": "4.0.0-canary.20220707.1",
39
+ "@umijs/bundler-utils": "4.0.0-canary.20220707.1",
40
+ "@umijs/mfsu": "4.0.0-canary.20220707.1",
41
+ "@umijs/utils": "4.0.0-canary.20220707.1",
42
42
  "cors": "^2.8.5",
43
43
  "css-loader": "6.7.1",
44
44
  "es5-imcompatible-versions": "^0.1.73",