@umijs/bundler-webpack 4.0.0-rc.9 → 4.0.2

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 (78) hide show
  1. package/client/client/client.js +65 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
  4. package/compiled/cssnano/index.js +6 -6
  5. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  6. package/compiled/{tapable → react-refresh}/LICENSE +6 -6
  7. package/compiled/react-refresh/index.js +9 -7
  8. package/compiled/react-refresh/package.json +1 -0
  9. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  10. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  11. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  12. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  13. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  14. package/compiled/webpack/RuleSetCompiler.js +1 -0
  15. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  16. package/compiled/webpack/deepImports.json +6 -1
  17. package/compiled/webpack/index.js +3978 -3167
  18. package/compiled/webpack/types.d.ts +606 -171
  19. package/compiled/webpack-dev-middleware/index.js +8 -7
  20. package/compiled/webpack-manifest-plugin/index.js +1 -1
  21. package/dist/build.d.ts +1 -0
  22. package/dist/build.js +49 -56
  23. package/dist/cli.js +6 -15
  24. package/dist/client/client.js +52 -50
  25. package/dist/config/_sampleFeature.js +6 -17
  26. package/dist/config/assetRules.js +33 -55
  27. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  28. package/dist/config/compressPlugin.js +89 -70
  29. package/dist/config/config.d.ts +2 -0
  30. package/dist/config/config.js +182 -179
  31. package/dist/config/copyPlugin.js +29 -40
  32. package/dist/config/cssRules.js +114 -83
  33. package/dist/config/definePlugin.js +11 -19
  34. package/dist/config/detectDeadCodePlugin.js +16 -21
  35. package/dist/config/fastRefreshPlugin.js +11 -22
  36. package/dist/config/forkTSCheckerPlugin.js +11 -22
  37. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  38. package/dist/config/ignorePlugin.js +10 -21
  39. package/dist/config/javaScriptRules.d.ts +1 -0
  40. package/dist/config/javaScriptRules.js +152 -136
  41. package/dist/config/manifestPlugin.d.ts +1 -1
  42. package/dist/config/manifestPlugin.js +10 -18
  43. package/dist/config/miniCSSExtractPlugin.js +15 -23
  44. package/dist/config/nodePolyfill.js +14 -20
  45. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  46. package/dist/config/nodePrefixPlugin.js +14 -0
  47. package/dist/config/progressPlugin.js +7 -18
  48. package/dist/config/purgecssWebpackPlugin.js +15 -26
  49. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  50. package/dist/config/ssrPlugin.d.ts +11 -0
  51. package/dist/config/ssrPlugin.js +66 -0
  52. package/dist/config/svgRules.js +35 -44
  53. package/dist/constants.d.ts +1 -0
  54. package/dist/constants.js +7 -1
  55. package/dist/dev.d.ts +4 -0
  56. package/dist/dev.js +113 -93
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.js +16 -0
  59. package/dist/loader/svgr.js +4 -13
  60. package/dist/loader/swc.js +9 -14
  61. package/dist/plugins/ProgressPlugin.js +3 -3
  62. package/dist/plugins/RuntimePublicPathPlugin.js +4 -1
  63. package/dist/schema.d.ts +1 -2
  64. package/dist/schema.js +21 -6
  65. package/dist/server/server.d.ts +3 -1
  66. package/dist/server/server.js +165 -159
  67. package/dist/server/ws.d.ts +7 -2
  68. package/dist/types.d.ts +3 -0
  69. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  70. package/dist/utils/getEsBuildTarget.js +12 -0
  71. package/package.json +23 -21
  72. package/compiled/tapable/index.js +0 -1
  73. package/compiled/tapable/package.json +0 -1
  74. package/compiled/tapable/tapable.d.ts +0 -116
  75. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  76. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
  77. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
  78. package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
4
+ const utils_1 = require("@umijs/utils");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const constants_1 = require("../constants");
8
+ const PLUGIN_NAME = 'SSR_PLUGIN';
9
+ class SSRPlugin {
10
+ constructor(opts) {
11
+ this.opts = opts;
12
+ this.manifest = new Map();
13
+ }
14
+ apply(compiler) {
15
+ // ref: https://github.com/webdeveric/webpack-assets-manifest
16
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
17
+ compilation.hooks.processAssets.tap(PLUGIN_NAME, () => {
18
+ const publicPath = compiler.options.output.publicPath || '/';
19
+ const assets = compilation.getAssets().filter((asset) => {
20
+ if (asset.info.hotModuleReplacement) {
21
+ return false;
22
+ }
23
+ return true;
24
+ });
25
+ assets.forEach((asset) => {
26
+ if (asset.info.sourceFilename) {
27
+ this.manifest.set(asset.info.sourceFilename, publicPath + asset.name);
28
+ }
29
+ });
30
+ const stats = compilation.getStats().toJson({
31
+ all: false,
32
+ assets: true,
33
+ cachedAssets: true,
34
+ cachedModules: true,
35
+ });
36
+ const { assetsByChunkName } = stats;
37
+ Object.keys(assetsByChunkName).forEach((chunkName) => {
38
+ assetsByChunkName[chunkName].forEach((filename) => {
39
+ const ext = (0, path_1.extname)(filename.split(/[?#]/)[0]);
40
+ if (!filename.includes('.hot-update.')) {
41
+ this.manifest.set(chunkName + ext, publicPath + filename);
42
+ }
43
+ });
44
+ });
45
+ const assetsSource = JSON.stringify({
46
+ assets: Object.fromEntries(this.manifest),
47
+ }, null, 2);
48
+ if (process.env.NODE_ENV === 'production' ||
49
+ this.opts.userConfig.writeToDisk) {
50
+ compilation.emitAsset('build-manifest.json', new webpack_1.sources.RawSource(assetsSource, false));
51
+ }
52
+ else {
53
+ const outputPath = compiler.options.output.path;
54
+ utils_1.fsExtra.mkdirpSync(outputPath);
55
+ (0, fs_1.writeFileSync)((0, path_1.join)(outputPath, 'build-manifest.json'), assetsSource, 'utf-8');
56
+ }
57
+ });
58
+ });
59
+ }
60
+ }
61
+ function addSSRPlugin(opts) {
62
+ if (opts.userConfig.ssr && opts.name !== constants_1.MFSU_NAME) {
63
+ opts.config.plugin('ssr-plugin').use(SSRPlugin, [opts]);
64
+ }
65
+ }
66
+ exports.default = addSSRPlugin;
@@ -1,57 +1,48 @@
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
- const svgrRule = config.module.rule('svgr');
19
- svgrRule
20
- .test(/\.svg$/)
21
- .issuer(/\.[jt]sx?$/)
22
- .type('javascript/auto')
23
- .use('svgr-loader')
24
- .loader(require.resolve('../loader/svgr'))
25
- .options(Object.assign(Object.assign({ svgoConfig: Object.assign({ plugins: [
26
- {
27
- name: 'preset-default',
28
- params: {
29
- overrides: {
30
- removeTitle: false,
31
- },
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,
32
23
  },
33
24
  },
34
- ] }, svgo) }, svgr), { svgo: !!svgo }))
35
- .end()
36
- .use('url-loader')
37
- .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
38
- .end();
39
- }
40
- if (svgo === false) {
41
- const svgRule = config.module.rule('svg');
42
- svgRule
43
- .test(/\.svg$/)
44
- .use('url-loader')
45
- .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
46
- return;
47
- }
25
+ },
26
+ 'prefixIds',
27
+ ],
28
+ ...svgo,
29
+ },
30
+ ...svgr,
31
+ svgo: !!svgo,
32
+ })
33
+ .end()
34
+ .use('url-loader')
35
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
36
+ .end();
37
+ }
38
+ if (svgo !== false) {
48
39
  const svgRule = config.module.rule('svg');
49
40
  svgRule
50
41
  .test(/\.svg$/)
51
42
  .use('svgo-loader')
52
43
  .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
53
- .options(Object.assign({ configFile: false }, svgo))
44
+ .options({ configFile: false, ...svgo })
54
45
  .end();
55
- });
46
+ }
56
47
  }
57
48
  exports.addSVGRules = addSVGRules;
@@ -12,3 +12,4 @@ export declare enum MESSAGE_TYPE {
12
12
  export declare const DEFAULT_BROWSER_TARGETS: {
13
13
  chrome: number;
14
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.DEFAULT_BROWSER_TARGETS = 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';
@@ -16,3 +16,9 @@ var MESSAGE_TYPE;
16
16
  exports.DEFAULT_BROWSER_TARGETS = {
17
17
  chrome: 80,
18
18
  };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];
package/dist/dev.d.ts CHANGED
@@ -4,6 +4,8 @@ declare type IOpts = {
4
4
  afterMiddlewares?: any[];
5
5
  beforeMiddlewares?: any[];
6
6
  onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
7
9
  port?: number;
8
10
  host?: string;
9
11
  babelPreset?: any;
@@ -14,8 +16,10 @@ declare type IOpts = {
14
16
  extraBabelPlugins?: any[];
15
17
  extraBabelPresets?: any[];
16
18
  cwd: string;
19
+ rootDir?: string;
17
20
  config: IConfig;
18
21
  entry: Record<string, string>;
19
22
  } & Pick<IConfigOpts, 'cache'>;
23
+ export declare function stripUndefined(obj: any): any;
20
24
  export declare function dev(opts: IOpts): Promise<void>;
21
25
  export {};
package/dist/dev.js CHANGED
@@ -1,114 +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");
17
8
  const utils_1 = require("@umijs/utils");
9
+ const fs_1 = require("fs");
18
10
  const path_1 = require("path");
19
11
  const webpack_1 = __importDefault(require("../compiled/webpack"));
20
12
  const config_1 = require("./config/config");
21
13
  const constants_1 = require("./constants");
22
14
  const server_1 = require("./server/server");
23
15
  const types_1 = require("./types");
24
- function dev(opts) {
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) {
25
26
  var _a, _b, _c, _d, _e, _f;
26
27
  var _g;
27
- return __awaiter(this, void 0, void 0, function* () {
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({
35
- implementor: webpack_1.default,
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.cwd, 'node_modules/.cache/mfsu'),
44
- getCacheDependency() {
45
- var _a;
46
- return {
47
- version: require('../package.json').version,
48
- esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
49
- };
50
- },
51
- });
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.`);
52
33
  }
53
- const webpackConfig = yield (0, config_1.getConfig)({
54
- cwd: opts.cwd,
55
- env: types_1.Env.development,
56
- entry: opts.entry,
57
- userConfig: opts.config,
58
- babelPreset: opts.babelPreset,
59
- extraBabelPlugins: [
60
- ...(opts.beforeBabelPlugins || []),
61
- ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
62
- ...(opts.extraBabelPlugins || []),
63
- ],
64
- extraBabelPresets: [
65
- ...(opts.beforeBabelPresets || []),
66
- ...(opts.extraBabelPresets || []),
67
- ],
68
- extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
69
- chainWebpack: opts.chainWebpack,
70
- modifyWebpackConfig: opts.modifyWebpackConfig,
71
- hmr: true,
72
- analyze: process.env.ANALYZE,
73
- cache: opts.cache,
74
- });
75
- const depConfig = yield (0, config_1.getConfig)({
76
- cwd: opts.cwd,
77
- env: types_1.Env.development,
78
- entry: opts.entry,
79
- userConfig: opts.config,
80
- hash: true,
81
- staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
82
- name: constants_1.MFSU_NAME,
83
- chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
84
- cache: {
85
- buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
86
- cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
34
+ mfsu = new mfsu_1.MFSU({
35
+ implementor: webpack_1.default,
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
+ });
87
55
  },
88
56
  });
89
- (_g = webpackConfig.resolve).alias || (_g.alias = {});
90
- // TODO: REMOVE ME
91
- ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
92
- // @ts-ignore
93
- webpackConfig.resolve.alias[dep] = require.resolve(dep);
94
- });
95
- yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
96
- config: webpackConfig,
97
- depConfig: depConfig,
98
- }));
99
- yield (0, server_1.createServer)({
100
- webpackConfig,
101
- userConfig: opts.config,
102
- cwd: opts.cwd,
103
- beforeMiddlewares: [
104
- ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
105
- ...(opts.beforeMiddlewares || []),
106
- ],
107
- port: opts.port,
108
- host: opts.host,
109
- afterMiddlewares: [...(opts.afterMiddlewares || [])],
110
- onDevCompileDone: opts.onDevCompileDone,
111
- });
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,
112
132
  });
113
133
  }
114
134
  exports.dev = dev;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
+ import * as parcelCSS from '@parcel/css';
1
2
  import type webpack from '../compiled/webpack';
3
+ import './requireHook';
2
4
  export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
3
5
  export type { Compiler, Stats } from '../compiled/webpack';
4
6
  export * from './build';
5
7
  export * from './config/config';
6
8
  export * from './dev';
7
9
  export * from './schema';
10
+ export { parcelCSS };
8
11
  export { webpack };
package/dist/index.js CHANGED
@@ -10,10 +10,26 @@ 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
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.parcelCSS = void 0;
30
+ const parcelCSS = __importStar(require("@parcel/css"));
31
+ exports.parcelCSS = parcelCSS;
32
+ require("./requireHook");
17
33
  __exportStar(require("./build"), exports);
18
34
  __exportStar(require("./config/config"), exports);
19
35
  __exportStar(require("./dev"), exports);
@@ -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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -22,9 +13,9 @@ const plugin_svgo_1 = __importDefault(require("@svgr/plugin-svgo"));
22
13
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
23
14
  const path_1 = require("path");
24
15
  const util_1 = require("util");
25
- const tranformSvg = (0, util_1.callbackify)((contents, options, state) => __awaiter(void 0, void 0, void 0, function* () {
26
- const jsCode = yield (0, core_1.transform)(contents, options, state);
27
- const result = yield (0, esbuild_1.transform)(jsCode, {
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, {
28
19
  loader: 'tsx',
29
20
  target: 'es2015',
30
21
  });
@@ -32,7 +23,7 @@ const tranformSvg = (0, util_1.callbackify)((contents, options, state) => __awai
32
23
  throw new Error(`Error while transforming using Esbuild`);
33
24
  }
34
25
  return result.code;
35
- }));
26
+ });
36
27
  function svgrLoader(contents) {
37
28
  this.cacheable && this.cacheable();
38
29
  const callback = this.async();
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  const core_1 = require("@swc/core");
15
4
  const types_1 = require("../types");
@@ -54,11 +43,17 @@ function swcLoader(contents) {
54
43
  // 启用异步模式
55
44
  const callback = this.async();
56
45
  const loaderOpts = this.getOptions();
57
- const { sync = false, parseMap = false } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap"]);
46
+ const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
58
47
  const filename = this.resourcePath;
59
- const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
48
+ const swcOpts = {
49
+ ...getBaseOpts({
50
+ filename,
51
+ }),
60
52
  filename,
61
- })), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
53
+ sourceMaps: this.sourceMap,
54
+ sourceFileName: filename,
55
+ ...otherOpts,
56
+ };
62
57
  try {
63
58
  if (sync) {
64
59
  const output = (0, core_1.transformSync)(contents, swcOpts);
@@ -12,8 +12,9 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
12
12
  };
13
13
  }
14
14
  apply(compiler) {
15
+ const prefix = this.options.name ? `[${this.options.name}]` : '[Webpack]';
15
16
  compiler.hooks.invalid.tap(PLUGIN_NAME, () => {
16
- utils_1.logger.wait('Compiling...');
17
+ utils_1.logger.wait(`${prefix} Compiling...`);
17
18
  });
18
19
  compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
19
20
  const { errors, warnings } = stats.toJson({
@@ -32,8 +33,7 @@ class UmiProgressPlugin extends webpack_1.ProgressPlugin {
32
33
  });
33
34
  }
34
35
  else {
35
- const prefix = this.options.name ? `${this.options.name} ` : '';
36
- utils_1.logger.event(`${prefix}Compiled successfully in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
36
+ utils_1.logger.event(`${prefix} Compiled in ${stats.endTime - stats.startTime} ms (${stats.compilation.modules.size} modules)`);
37
37
  }
38
38
  });
39
39
  }
@@ -10,8 +10,11 @@ class RuntimePublicPathPlugin {
10
10
  // The hook to get the public path ('__webpack_require__.p')
11
11
  // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
12
  if (module.constructor.name === 'PublicPathRuntimeModule') {
13
+ // If current public path is handled by mini-css-extract-plugin, skip it
14
+ if (module.getGeneratedCode().includes('webpack:///mini-css-extract-plugin'))
15
+ return;
13
16
  // @ts-ignore
14
- module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
17
+ module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
15
18
  }
16
19
  });
17
20
  });
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
@@ -4,18 +4,30 @@ exports.getSchemas = void 0;
4
4
  const types_1 = require("./types");
5
5
  const options = [
6
6
  'cheap-source-map',
7
- 'cheap-eval-source-map',
8
- 'cheap-hidden-source-map',
9
- 'cheap-inline-source-map',
10
7
  'cheap-module-source-map',
11
- 'cheap-module-eval-source-map',
12
- 'cheap-module-hidden-source-map',
13
- 'cheap-module-inline-source-map',
14
8
  'eval',
15
9
  'eval-source-map',
10
+ 'eval-cheap-source-map',
11
+ 'eval-cheap-module-source-map',
12
+ 'eval-nosources-cheap-source-map',
13
+ 'eval-nosources-cheap-module-source-map',
14
+ 'eval-nosources-source-map',
16
15
  'source-map',
17
16
  'hidden-source-map',
17
+ 'hidden-nosources-cheap-source-map',
18
+ 'hidden-nosources-cheap-module-source-map',
19
+ 'hidden-nosources-source-map',
20
+ 'hidden-cheap-source-map',
21
+ 'hidden-cheap-module-source-map',
18
22
  'inline-source-map',
23
+ 'inline-cheap-source-map',
24
+ 'inline-cheap-module-source-map',
25
+ 'inline-nosources-cheap-source-map',
26
+ 'inline-nosources-cheap-module-source-map',
27
+ 'inline-nosources-source-map',
28
+ 'nosources-source-map',
29
+ 'nosources-cheap-source-map',
30
+ 'nosources-cheap-module-source-map',
19
31
  ];
20
32
  const DEVTOOL_REGEX = new RegExp('^' + // start of string
21
33
  '(#@|@|#)?' + // maybe one of the pragmas
@@ -40,12 +52,14 @@ function getSchemas() {
40
52
  devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
41
53
  esm: (Joi) => Joi.object(),
42
54
  externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
55
+ extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
43
56
  extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
44
57
  extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
45
58
  extraPostCSSPlugins: (Joi) => Joi.array(),
46
59
  fastRefresh: (Joi) => Joi.boolean(),
47
60
  forkTSChecker: (Joi) => Joi.object(),
48
61
  hash: (Joi) => Joi.boolean(),
62
+ https: (Joi) => Joi.object(),
49
63
  ignoreMomentLocale: (Joi) => Joi.boolean(),
50
64
  inlineLimit: (Joi) => Joi.number(),
51
65
  jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
@@ -61,6 +75,7 @@ function getSchemas() {
61
75
  chainWebpack: Joi.function(),
62
76
  esbuild: Joi.boolean(),
63
77
  mfName: Joi.string(),
78
+ runtimePublicPath: Joi.boolean(),
64
79
  }), Joi.boolean()),
65
80
  outputPath: (Joi) => Joi.string(),
66
81
  postcssLoader: (Joi) => Joi.object(),