@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-canary.202200505.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.
Files changed (197) hide show
  1. package/client/client/client.js +65 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/autoprefixer/browserslist/index.d.ts +13 -7
  4. package/compiled/autoprefixer/index.js +3 -3
  5. package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
  6. package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
  7. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  8. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  9. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
  10. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  11. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  12. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  13. package/compiled/autoprefixer/postcss/lib/node.d.ts +38 -4
  14. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  15. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  16. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  17. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  18. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  19. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  20. package/compiled/babel-loader/index.js +2 -2
  21. package/compiled/copy-webpack-plugin/939.index.js +1171 -0
  22. package/compiled/copy-webpack-plugin/index.js +16 -10
  23. package/compiled/copy-webpack-plugin/package.json +1 -1
  24. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  25. package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
  26. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  27. package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
  28. package/compiled/cssnano/index.js +12 -11
  29. package/compiled/cssnano/package.json +1 -1
  30. package/compiled/express.d.ts +2 -0
  31. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  32. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  33. package/compiled/fork-ts-checker-webpack-plugin/index.js +42 -0
  34. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  35. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  36. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  37. package/compiled/http-proxy-middleware/index.js +10 -10
  38. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  39. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  40. package/compiled/mini-css-extract-plugin/index.js +7970 -7445
  41. package/compiled/mini-css-extract-plugin/loader.js +179 -54
  42. package/compiled/mini-css-extract-plugin/package.json +1 -1
  43. package/compiled/mini-css-extract-plugin/utils.js +85 -24
  44. package/compiled/postcss-loader/index.js +1 -1
  45. package/compiled/react-refresh/LICENSE +21 -0
  46. package/compiled/react-refresh/index.js +9 -7
  47. package/compiled/react-refresh/package.json +1 -0
  48. package/compiled/sass-loader/index.js +1 -1
  49. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  50. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  51. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  52. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  53. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  54. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  55. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  56. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  57. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  58. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  59. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  60. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  61. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  62. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  63. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  64. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  65. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  66. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  67. package/compiled/schema-utils/index.js +8 -2
  68. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  69. package/compiled/style-loader/index.js +1 -1
  70. package/compiled/terser/index.js +1 -1
  71. package/compiled/terser-webpack-plugin/index.js +393 -517
  72. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  73. package/compiled/terser-webpack-plugin/minify.js +10 -3
  74. package/compiled/terser-webpack-plugin/package.json +1 -1
  75. package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
  76. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  77. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
  78. package/compiled/terser-webpack-plugin/utils.js +118 -25
  79. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  80. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  81. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  82. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  83. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  84. package/compiled/webpack/RuleSetCompiler.js +1 -0
  85. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  86. package/compiled/webpack/deepImports.json +6 -1
  87. package/compiled/webpack/index.js +13409 -5746
  88. package/compiled/webpack/types.d.ts +606 -171
  89. package/compiled/webpack-dev-middleware/index.js +11 -5
  90. package/compiled/webpack-dev-middleware/package.json +1 -1
  91. package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
  92. package/compiled/webpack-manifest-plugin/index.js +1 -0
  93. package/compiled/webpack-manifest-plugin/package.json +1 -0
  94. package/compiled/webpack-sources/index.js +1 -1
  95. package/compiled/ws/index.d.ts +1 -2
  96. package/compiled/ws/index.js +1 -1
  97. package/dist/build.d.ts +6 -3
  98. package/dist/build.js +48 -56
  99. package/dist/cli.js +10 -22
  100. package/dist/client/client.js +57 -51
  101. package/dist/config/_sampleFeature.js +6 -17
  102. package/dist/config/assetRules.js +44 -51
  103. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  104. package/dist/config/compressPlugin.js +70 -64
  105. package/dist/config/config.d.ts +9 -2
  106. package/dist/config/config.js +184 -144
  107. package/dist/config/copyPlugin.js +29 -40
  108. package/dist/config/cssRules.js +93 -83
  109. package/dist/config/definePlugin.js +11 -19
  110. package/dist/config/detectDeadCode.d.ts +12 -0
  111. package/dist/config/detectDeadCode.js +120 -0
  112. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  113. package/dist/config/detectDeadCodePlugin.js +70 -0
  114. package/dist/config/fastRefreshPlugin.js +11 -22
  115. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  116. package/dist/config/forkTSCheckerPlugin.js +23 -0
  117. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  118. package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
  119. package/dist/config/ignorePlugin.js +10 -21
  120. package/dist/config/javaScriptRules.d.ts +2 -0
  121. package/dist/config/javaScriptRules.js +153 -131
  122. package/dist/config/manifestPlugin.d.ts +11 -0
  123. package/dist/config/manifestPlugin.js +17 -0
  124. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  125. package/dist/config/miniCSSExtractPlugin.js +12 -24
  126. package/dist/config/nodePolyfill.js +14 -20
  127. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  128. package/dist/config/nodePrefixPlugin.js +14 -0
  129. package/dist/config/progressPlugin.js +7 -18
  130. package/dist/config/purgecssWebpackPlugin.js +15 -26
  131. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  132. package/dist/config/svgRules.d.ts +1 -0
  133. package/dist/config/svgRules.js +45 -48
  134. package/dist/constants.d.ts +4 -0
  135. package/dist/constants.js +10 -1
  136. package/dist/dev.d.ts +8 -2
  137. package/dist/dev.js +117 -66
  138. package/dist/index.d.ts +4 -1
  139. package/dist/index.js +5 -1
  140. package/dist/loader/svgr.d.ts +4 -0
  141. package/dist/loader/svgr.js +58 -0
  142. package/dist/loader/swc.d.ts +4 -0
  143. package/dist/loader/swc.js +74 -0
  144. package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -36
  145. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  146. package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
  147. package/dist/plugins/ProgressPlugin.js +2 -2
  148. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  149. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  150. package/dist/requireHook.js +1 -1
  151. package/dist/schema.js +23 -11
  152. package/dist/server/server.d.ts +2 -1
  153. package/dist/server/server.js +165 -130
  154. package/dist/server/ws.d.ts +6 -3
  155. package/dist/server/ws.js +1 -1
  156. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  157. package/dist/swcPlugins/autoCSSModules.js +16 -17
  158. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  159. package/dist/swcPlugins/changeImportFromString.js +10 -0
  160. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  161. package/dist/swcPlugins/lockCoreJS.js +24 -0
  162. package/dist/types.d.ts +19 -0
  163. package/dist/types.js +1 -0
  164. package/dist/utils/depMatch.js +1 -1
  165. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  166. package/dist/utils/getEsBuildTarget.js +12 -0
  167. package/package.json +68 -67
  168. package/compiled/@svgr/webpack/.svgo.yml +0 -75
  169. package/compiled/@svgr/webpack/LICENSE +0 -7
  170. package/compiled/@svgr/webpack/index.js +0 -343
  171. package/compiled/@svgr/webpack/package.json +0 -1
  172. package/compiled/css-loader/LICENSE +0 -20
  173. package/compiled/css-loader/api.js +0 -102
  174. package/compiled/css-loader/getUrl.js +0 -29
  175. package/compiled/css-loader/index.js +0 -2
  176. package/compiled/css-loader/noSourceMaps.js +0 -5
  177. package/compiled/css-loader/package.json +0 -1
  178. package/compiled/css-loader/sourceMaps.js +0 -22
  179. package/compiled/express/LICENSE +0 -24
  180. package/compiled/express/body-parser/index.d.ts +0 -104
  181. package/compiled/express/connect/index.d.ts +0 -93
  182. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  183. package/compiled/express/index.d.ts +0 -133
  184. package/compiled/express/index.js +0 -338
  185. package/compiled/express/mime/index.d.ts +0 -35
  186. package/compiled/express/package.json +0 -1
  187. package/compiled/express/qs/index.d.ts +0 -62
  188. package/compiled/express/range-parser/index.d.ts +0 -35
  189. package/compiled/express/serve-static/index.d.ts +0 -108
  190. package/compiled/less/index.js +0 -31
  191. package/compiled/less/package.json +0 -1
  192. package/compiled/swc-loader/LICENSE +0 -25
  193. package/compiled/swc-loader/index.js +0 -1
  194. package/compiled/swc-loader/package.json +0 -1
  195. package/compiled/tapable/index.js +0 -1
  196. package/compiled/tapable/package.json +0 -1
  197. package/compiled/tapable/tapable.d.ts +0 -116
@@ -1,56 +1,53 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addSVGRules = void 0;
13
- function addSVGRules(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig } = opts;
16
- const { svgr, svgo } = userConfig;
17
- if (svgr) {
18
- // https://react-svgr.com/docs/webpack/#handle-svg-in-css-sass-or-less
19
- // https://github.com/gregberge/svgr/issues/551#issuecomment-883073902
20
- // https://github.com/webpack/webpack/issues/9309
21
- const svgrRule = config.module.rule('svgr');
22
- svgrRule
23
- .test(/\.svg$/)
24
- .issuer(/\.[jt]sx?$/)
25
- .type('javascript/auto')
26
- .use('babel-loader')
27
- .loader(require.resolve('@umijs/bundler-webpack/compiled/babel-loader'))
28
- .end()
29
- .use('svgr-loader')
30
- .loader(require.resolve('@umijs/bundler-webpack/compiled/@svgr/webpack'))
31
- .options(Object.assign(Object.assign({ svgoConfig: {
32
- plugins: [{ removeViewBox: false }],
33
- } }, svgr), { svgo }))
34
- .end()
35
- .use('url-loader')
36
- .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
37
- .end();
38
- }
39
- if (svgo === false) {
40
- const svgRule = config.module.rule('svg');
41
- svgRule
42
- .test(/\.svg$/)
43
- .use('url-loader')
44
- .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
45
- return;
46
- }
4
+ async function addSVGRules(opts) {
5
+ const { config, userConfig } = opts;
6
+ const { svgr, svgo = {} } = userConfig;
7
+ if (svgr) {
8
+ const svgrRule = config.module.rule('svgr');
9
+ svgrRule
10
+ .test(/\.svg$/)
11
+ .issuer(/\.[jt]sx?$/)
12
+ .type('javascript/auto')
13
+ .use('svgr-loader')
14
+ .loader(require.resolve('../loader/svgr'))
15
+ .options({
16
+ svgoConfig: {
17
+ plugins: [
18
+ {
19
+ name: 'preset-default',
20
+ params: {
21
+ overrides: {
22
+ removeTitle: false,
23
+ },
24
+ },
25
+ },
26
+ ],
27
+ ...svgo,
28
+ },
29
+ ...svgr,
30
+ svgo: !!svgo,
31
+ })
32
+ .end()
33
+ .use('url-loader')
34
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
35
+ .end();
36
+ }
37
+ if (svgo === false) {
47
38
  const svgRule = config.module.rule('svg');
48
39
  svgRule
49
40
  .test(/\.svg$/)
50
- .use('svgo-loader')
51
- .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
52
- .options(Object.assign({ configFile: false }, svgo))
53
- .end();
54
- });
41
+ .use('url-loader')
42
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
43
+ return;
44
+ }
45
+ const svgRule = config.module.rule('svg');
46
+ svgRule
47
+ .test(/\.svg$/)
48
+ .use('svgo-loader')
49
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
50
+ .options({ configFile: false, ...svgo })
51
+ .end();
55
52
  }
56
53
  exports.addSVGRules = addSVGRules;
@@ -9,3 +9,7 @@ export declare enum MESSAGE_TYPE {
9
9
  stillOk = "still-ok",
10
10
  invalid = "invalid"
11
11
  }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
3
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
4
4
  exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
5
5
  exports.DEFAULT_OUTPUT_PATH = 'dist';
6
6
  exports.MFSU_NAME = 'MFSU';
@@ -13,3 +13,12 @@ var MESSAGE_TYPE;
13
13
  MESSAGE_TYPE["stillOk"] = "still-ok";
14
14
  MESSAGE_TYPE["invalid"] = "invalid";
15
15
  })(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
16
+ exports.DEFAULT_BROWSER_TARGETS = {
17
+ chrome: 80,
18
+ };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];
package/dist/dev.d.ts CHANGED
@@ -1,10 +1,14 @@
1
+ import { IOpts as IConfigOpts } from './config/config';
1
2
  import { IConfig } from './types';
2
- interface IOpts {
3
+ declare type IOpts = {
3
4
  afterMiddlewares?: any[];
4
5
  beforeMiddlewares?: any[];
5
6
  onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
6
9
  port?: number;
7
10
  host?: string;
11
+ babelPreset?: any;
8
12
  chainWebpack?: Function;
9
13
  modifyWebpackConfig?: Function;
10
14
  beforeBabelPlugins?: any[];
@@ -12,8 +16,10 @@ interface IOpts {
12
16
  extraBabelPlugins?: any[];
13
17
  extraBabelPresets?: any[];
14
18
  cwd: string;
19
+ rootDir?: string;
15
20
  config: IConfig;
16
21
  entry: Record<string, string>;
17
- }
22
+ } & Pick<IConfigOpts, 'cache'>;
23
+ export declare function stripUndefined(obj: any): any;
18
24
  export declare function dev(opts: IOpts): Promise<void>;
19
25
  export {};
package/dist/dev.js CHANGED
@@ -1,83 +1,134 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.dev = void 0;
6
+ exports.dev = exports.stripUndefined = void 0;
16
7
  const mfsu_1 = require("@umijs/mfsu");
8
+ const utils_1 = require("@umijs/utils");
9
+ const fs_1 = require("fs");
10
+ const path_1 = require("path");
17
11
  const webpack_1 = __importDefault(require("../compiled/webpack"));
18
12
  const config_1 = require("./config/config");
19
13
  const constants_1 = require("./constants");
20
14
  const server_1 = require("./server/server");
21
15
  const types_1 = require("./types");
22
- function dev(opts) {
23
- var _a;
24
- var _b;
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const mfsu = new mfsu_1.MFSU({
16
+ function stripUndefined(obj) {
17
+ Object.keys(obj).forEach((key) => {
18
+ if (obj[key] === undefined) {
19
+ delete obj[key];
20
+ }
21
+ });
22
+ return obj;
23
+ }
24
+ exports.stripUndefined = stripUndefined;
25
+ async function dev(opts) {
26
+ var _a, _b, _c, _d, _e, _f;
27
+ var _g;
28
+ const enableMFSU = opts.config.mfsu !== false;
29
+ let mfsu = null;
30
+ if (enableMFSU) {
31
+ if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
32
+ utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
33
+ }
34
+ mfsu = new mfsu_1.MFSU({
27
35
  implementor: webpack_1.default,
28
36
  buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
37
+ depBuildConfig: {
38
+ extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
39
+ },
40
+ mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
41
+ runtimePublicPath: opts.config.runtimePublicPath,
42
+ tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
43
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules/.cache/mfsu'),
44
+ onMFSUProgress: opts.onMFSUProgress,
45
+ getCacheDependency() {
46
+ return stripUndefined({
47
+ version: require('../package.json').version,
48
+ mfsu: opts.config.mfsu,
49
+ alias: opts.config.alias,
50
+ externals: opts.config.externals,
51
+ theme: opts.config.theme,
52
+ runtimePublicPath: opts.config.runtimePublicPath,
53
+ publicPath: opts.config.publicPath,
54
+ });
55
+ },
29
56
  });
30
- const webpackConfig = yield (0, config_1.getConfig)({
31
- cwd: opts.cwd,
32
- env: types_1.Env.development,
33
- entry: opts.entry,
34
- userConfig: opts.config,
35
- extraBabelPlugins: [
36
- ...(opts.beforeBabelPlugins || []),
37
- ...mfsu.getBabelPlugins(),
38
- ...(opts.extraBabelPlugins || []),
39
- ],
40
- extraBabelPresets: [
41
- ...(opts.beforeBabelPresets || []),
42
- ...(opts.extraBabelPresets || []),
43
- ],
44
- chainWebpack: opts.chainWebpack,
45
- modifyWebpackConfig: opts.modifyWebpackConfig,
46
- hmr: true,
47
- analyze: process.env.ANALYZE,
48
- });
49
- const depConfig = yield (0, config_1.getConfig)({
50
- cwd: opts.cwd,
51
- env: types_1.Env.development,
52
- entry: opts.entry,
53
- userConfig: opts.config,
54
- hash: true,
55
- staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
56
- name: constants_1.MFSU_NAME,
57
- });
58
- (_b = webpackConfig.resolve).alias || (_b.alias = {});
59
- // TODO: REMOVE ME
60
- ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
61
- // @ts-ignore
62
- webpackConfig.resolve.alias[dep] = require.resolve(dep);
63
- });
64
- mfsu.setWebpackConfig({
65
- config: webpackConfig,
66
- depConfig: depConfig,
67
- });
68
- yield (0, server_1.createServer)({
69
- webpackConfig,
70
- userConfig: opts.config,
71
- cwd: opts.cwd,
72
- beforeMiddlewares: [
73
- ...mfsu.getMiddlewares(),
74
- ...(opts.beforeMiddlewares || []),
75
- ],
76
- port: opts.port,
77
- host: opts.host,
78
- afterMiddlewares: [...(opts.afterMiddlewares || [])],
79
- onDevCompileDone: opts.onDevCompileDone,
80
- });
57
+ }
58
+ const webpackConfig = await (0, config_1.getConfig)({
59
+ cwd: opts.cwd,
60
+ rootDir: opts.rootDir,
61
+ env: types_1.Env.development,
62
+ entry: opts.entry,
63
+ userConfig: opts.config,
64
+ babelPreset: opts.babelPreset,
65
+ extraBabelPlugins: [
66
+ ...(opts.beforeBabelPlugins || []),
67
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
68
+ ...(opts.extraBabelPlugins || []),
69
+ ],
70
+ extraBabelPresets: [
71
+ ...(opts.beforeBabelPresets || []),
72
+ ...(opts.extraBabelPresets || []),
73
+ ],
74
+ extraBabelIncludes: opts.config.extraBabelIncludes,
75
+ extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
76
+ chainWebpack: opts.chainWebpack,
77
+ modifyWebpackConfig: opts.modifyWebpackConfig,
78
+ hmr: true,
79
+ analyze: process.env.ANALYZE,
80
+ cache: opts.cache,
81
+ });
82
+ const depConfig = await (0, config_1.getConfig)({
83
+ cwd: opts.cwd,
84
+ rootDir: opts.rootDir,
85
+ env: types_1.Env.development,
86
+ entry: opts.entry,
87
+ userConfig: opts.config,
88
+ hash: true,
89
+ staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
90
+ name: constants_1.MFSU_NAME,
91
+ chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
92
+ cache: {
93
+ buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
94
+ cacheDirectory: (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
95
+ },
96
+ });
97
+ (_g = webpackConfig.resolve).alias || (_g.alias = {});
98
+ // TODO: REMOVE ME
99
+ ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
100
+ // @ts-ignore
101
+ webpackConfig.resolve.alias[dep] = require.resolve(dep);
102
+ });
103
+ await (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
104
+ config: webpackConfig,
105
+ depConfig: depConfig,
106
+ }));
107
+ if (mfsu &&
108
+ webpackConfig.cache &&
109
+ typeof webpackConfig.cache === 'object' &&
110
+ webpackConfig.cache.type === 'filesystem') {
111
+ const webpackCachePath = (0, path_1.join)(webpackConfig.cache.cacheDirectory, `default-development`, 'index.pack');
112
+ const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.depInfo.cacheFilePath);
113
+ const webpackCacheExists = (0, fs_1.existsSync)(webpackCachePath);
114
+ if (webpackCacheExists && !mfsuCacheExists) {
115
+ utils_1.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
116
+ utils_1.rimraf.sync(webpackConfig.cache.cacheDirectory);
117
+ }
118
+ }
119
+ await (0, server_1.createServer)({
120
+ webpackConfig,
121
+ userConfig: opts.config,
122
+ cwd: opts.cwd,
123
+ beforeMiddlewares: [
124
+ ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
125
+ ...(opts.beforeMiddlewares || []),
126
+ ],
127
+ port: opts.port,
128
+ host: opts.host,
129
+ afterMiddlewares: [...(opts.afterMiddlewares || [])],
130
+ onDevCompileDone: opts.onDevCompileDone,
131
+ onProgress: opts.onProgress,
81
132
  });
82
133
  }
83
134
  exports.dev = dev;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- export type { RequestHandler } from '../compiled/express';
1
+ import type webpack from '../compiled/webpack';
2
+ export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
3
+ export type { Compiler, Stats } from '../compiled/webpack';
2
4
  export * from './build';
3
5
  export * from './config/config';
4
6
  export * from './dev';
5
7
  export * from './schema';
8
+ export { webpack };
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -0,0 +1,4 @@
1
+ import { Config } from '@svgr/core';
2
+ import type { LoaderContext } from '../../compiled/webpack';
3
+ declare function svgrLoader(this: LoaderContext<Config>, contents: string): void;
4
+ export default svgrLoader;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // MIT: https://github.com/gregberge/svgr/blob/main/packages/webpack/src/index.ts
7
+ // TODO: prebuild @svgr/core @svgr/plugin-jsx @svgr/plugin-svgo
8
+ const core_1 = require("@svgr/core");
9
+ // @ts-ignore
10
+ const plugin_jsx_1 = __importDefault(require("@svgr/plugin-jsx"));
11
+ // @ts-ignore
12
+ const plugin_svgo_1 = __importDefault(require("@svgr/plugin-svgo"));
13
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
14
+ const path_1 = require("path");
15
+ const util_1 = require("util");
16
+ const tranformSvg = (0, util_1.callbackify)(async (contents, options, state) => {
17
+ const jsCode = await (0, core_1.transform)(contents, options, state);
18
+ const result = await (0, esbuild_1.transform)(jsCode, {
19
+ loader: 'tsx',
20
+ target: 'es2015',
21
+ });
22
+ if (!(result === null || result === void 0 ? void 0 : result.code)) {
23
+ throw new Error(`Error while transforming using Esbuild`);
24
+ }
25
+ return result.code;
26
+ });
27
+ function svgrLoader(contents) {
28
+ this.cacheable && this.cacheable();
29
+ const callback = this.async();
30
+ const options = this.getOptions();
31
+ const previousExport = (() => {
32
+ if (contents.startsWith('export '))
33
+ return contents;
34
+ const exportMatches = contents.match(/^module.exports\s*=\s*(.*)/);
35
+ return exportMatches ? `export default ${exportMatches[1]}` : null;
36
+ })();
37
+ const state = {
38
+ caller: {
39
+ name: 'svgr-loader',
40
+ previousExport,
41
+ defaultPlugins: [plugin_svgo_1.default, plugin_jsx_1.default],
42
+ },
43
+ filePath: (0, path_1.normalize)(this.resourcePath),
44
+ };
45
+ if (!previousExport) {
46
+ tranformSvg(contents, options, state, callback);
47
+ }
48
+ else {
49
+ this.fs.readFile(this.resourcePath, (err, result) => {
50
+ if (err) {
51
+ callback(err);
52
+ return;
53
+ }
54
+ tranformSvg(String(result), options, state, callback);
55
+ });
56
+ }
57
+ }
58
+ exports.default = svgrLoader;
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '../../compiled/webpack';
2
+ import { SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string): void;
4
+ export default swcLoader;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@swc/core");
4
+ const types_1 = require("../types");
5
+ function getBaseOpts({ filename }) {
6
+ const isTSFile = filename.endsWith('.ts');
7
+ const isTypeScript = isTSFile || filename.endsWith('.tsx');
8
+ const isDev = process.env.NODE_ENV === types_1.Env.development;
9
+ /**
10
+ * Not use swc auto polyfill , depend on `preset-umi/features/polyfill/polyfill` imported polyfill file
11
+ *
12
+ * @issue https://github.com/swc-project/swc/issues/2607
13
+ * https://github.com/swc-project/swc/issues/1604
14
+ */
15
+ const swcOpts = {
16
+ module: {
17
+ // @ts-ignore
18
+ type: 'es6',
19
+ ignoreDynamic: true,
20
+ },
21
+ jsc: {
22
+ parser: {
23
+ syntax: isTypeScript ? 'typescript' : 'ecmascript',
24
+ [isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
25
+ dynamicImport: isTypeScript,
26
+ },
27
+ target: 'es2015',
28
+ transform: {
29
+ react: {
30
+ runtime: 'automatic',
31
+ pragma: 'React.createElement',
32
+ pragmaFrag: 'React.Fragment',
33
+ throwIfNamespace: true,
34
+ development: isDev,
35
+ useBuiltins: true,
36
+ },
37
+ },
38
+ },
39
+ };
40
+ return swcOpts;
41
+ }
42
+ function swcLoader(contents) {
43
+ // 启用异步模式
44
+ const callback = this.async();
45
+ const loaderOpts = this.getOptions();
46
+ const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
47
+ const filename = this.resourcePath;
48
+ const swcOpts = {
49
+ ...getBaseOpts({
50
+ filename,
51
+ }),
52
+ filename,
53
+ sourceMaps: this.sourceMap,
54
+ sourceFileName: filename,
55
+ ...otherOpts,
56
+ };
57
+ try {
58
+ if (sync) {
59
+ const output = (0, core_1.transformSync)(contents, swcOpts);
60
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
61
+ }
62
+ else {
63
+ (0, core_1.transform)(contents, swcOpts).then((output) => {
64
+ callback(null, output.code, parseMap ? JSON.parse(output.map) : output.map);
65
+ }, (err) => {
66
+ callback(err);
67
+ });
68
+ }
69
+ }
70
+ catch (e) {
71
+ callback(e);
72
+ }
73
+ }
74
+ exports.default = swcLoader;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
13
4
  const webpack_sources_1 = require("@umijs/bundler-webpack/compiled/webpack-sources");
@@ -30,36 +21,32 @@ class ESBuildCSSMinifyPlugin {
30
21
  name: PLUGIN_NAME,
31
22
  stage: 400,
32
23
  additionalAssets: true,
33
- }, () => __awaiter(this, void 0, void 0, function* () {
34
- yield this.transformAssets(compilation);
35
- }));
24
+ }, async () => {
25
+ await this.transformAssets(compilation);
26
+ });
36
27
  });
37
28
  }
38
- transformAssets(compilation) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const { options: { devtool }, } = compilation.compiler;
41
- const sourcemap = this.options.sourcemap === undefined
42
- ? devtool && devtool
43
- : this.options.sourcemap;
44
- const assets = compilation.getAssets().filter((asset) => {
45
- return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
46
- });
47
- yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
48
- const { source, map } = asset.source.sourceAndMap();
49
- const sourceAsString = source.toString();
50
- const result = yield (0, esbuild_1.transform)(sourceAsString, {
51
- loader: 'css',
52
- sourcemap,
53
- sourcefile: asset.name,
54
- minify: true,
55
- });
56
- compilation.updateAsset(asset.name,
57
- // @ts-ignore
58
- sourcemap
59
- ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
60
- : new webpack_sources_1.RawSource(result.code), Object.assign(Object.assign({}, asset.info), { minimized: true }));
61
- })));
29
+ async transformAssets(compilation) {
30
+ const { options: { devtool }, } = compilation.compiler;
31
+ const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
32
+ const assets = compilation.getAssets().filter((asset) => {
33
+ return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
62
34
  });
35
+ await Promise.all(assets.map(async (asset) => {
36
+ const { source, map } = asset.source.sourceAndMap();
37
+ const sourceAsString = source.toString();
38
+ const result = await (0, esbuild_1.transform)(sourceAsString, {
39
+ loader: 'css',
40
+ sourcemap,
41
+ sourcefile: asset.name,
42
+ minify: true,
43
+ });
44
+ compilation.updateAsset(asset.name,
45
+ // @ts-ignore
46
+ sourcemap
47
+ ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
48
+ : new webpack_sources_1.RawSource(result.code), { ...asset.info, minimized: true });
49
+ }));
63
50
  }
64
51
  }
65
52
  exports.default = ESBuildCSSMinifyPlugin;
@@ -0,0 +1,10 @@
1
+ import type { TransformOptions } from '@parcel/css';
2
+ import type { Compiler } from '../../compiled/webpack/types';
3
+ declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
4
+ export declare class ParcelCSSMinifyPlugin {
5
+ private readonly options;
6
+ constructor(opts?: MinifyPluginOpts);
7
+ apply(compiler: Compiler): void;
8
+ private transformAssets;
9
+ }
10
+ export {};