@umijs/bundler-webpack 4.0.0-rc.13 → 4.0.0-rc.16

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 (42) hide show
  1. package/client/client/client.js +15 -7
  2. package/dist/build.js +48 -58
  3. package/dist/cli.js +6 -15
  4. package/dist/client/client.js +48 -53
  5. package/dist/config/_sampleFeature.js +6 -17
  6. package/dist/config/assetRules.js +44 -55
  7. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  8. package/dist/config/compressPlugin.js +68 -76
  9. package/dist/config/config.d.ts +1 -0
  10. package/dist/config/config.js +177 -184
  11. package/dist/config/copyPlugin.js +29 -40
  12. package/dist/config/cssRules.js +93 -83
  13. package/dist/config/definePlugin.js +11 -19
  14. package/dist/config/detectDeadCodePlugin.js +16 -21
  15. package/dist/config/fastRefreshPlugin.js +11 -22
  16. package/dist/config/forkTSCheckerPlugin.js +11 -22
  17. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  18. package/dist/config/ignorePlugin.js +10 -21
  19. package/dist/config/javaScriptRules.d.ts +1 -0
  20. package/dist/config/javaScriptRules.js +149 -136
  21. package/dist/config/manifestPlugin.js +10 -18
  22. package/dist/config/miniCSSExtractPlugin.js +12 -23
  23. package/dist/config/nodePolyfill.js +14 -20
  24. package/dist/config/nodePrefixPlugin.js +8 -19
  25. package/dist/config/progressPlugin.js +7 -18
  26. package/dist/config/purgecssWebpackPlugin.js +15 -26
  27. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  28. package/dist/config/svgRules.js +43 -47
  29. package/dist/dev.js +103 -100
  30. package/dist/loader/svgr.js +4 -13
  31. package/dist/loader/swc.js +9 -14
  32. package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
  33. package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
  34. package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
  35. package/dist/schema.js +19 -6
  36. package/dist/server/server.d.ts +1 -1
  37. package/dist/server/server.js +161 -182
  38. package/dist/server/ws.d.ts +3 -1
  39. package/dist/types.d.ts +3 -6
  40. package/package.json +10 -10
  41. package/dist/server/https.d.ts +0 -5
  42. package/dist/server/https.js +0 -73
@@ -1,57 +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
- 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
+ ],
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) {
48
38
  const svgRule = config.module.rule('svg');
49
39
  svgRule
50
40
  .test(/\.svg$/)
51
- .use('svgo-loader')
52
- .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
53
- .options(Object.assign({ configFile: false }, svgo))
54
- .end();
55
- });
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();
56
52
  }
57
53
  exports.addSVGRules = addSVGRules;
package/dist/dev.js CHANGED
@@ -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
  };
@@ -15,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
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");
@@ -30,102 +22,113 @@ function stripUndefined(obj) {
30
22
  return obj;
31
23
  }
32
24
  exports.stripUndefined = stripUndefined;
33
- function dev(opts) {
25
+ async function dev(opts) {
34
26
  var _a, _b, _c, _d, _e, _f;
35
27
  var _g;
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const enableMFSU = opts.config.mfsu !== false;
38
- let mfsu = null;
39
- if (enableMFSU) {
40
- if (opts.config.srcTranspiler === types_1.Transpiler.swc) {
41
- utils_1.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
42
- }
43
- mfsu = new mfsu_1.MFSU({
44
- implementor: webpack_1.default,
45
- buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
46
- depBuildConfig: {
47
- extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
48
- },
49
- mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
50
- runtimePublicPath: opts.config.runtimePublicPath,
51
- tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
52
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules/.cache/mfsu'),
53
- onMFSUProgress: opts.onMFSUProgress,
54
- getCacheDependency() {
55
- return stripUndefined({
56
- version: require('../package.json').version,
57
- mfsu: opts.config.mfsu,
58
- alias: opts.config.alias,
59
- externals: opts.config.externals,
60
- theme: opts.config.theme,
61
- runtimePublicPath: opts.config.runtimePublicPath,
62
- publicPath: opts.config.publicPath,
63
- });
64
- },
65
- });
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.`);
66
33
  }
67
- const webpackConfig = yield (0, config_1.getConfig)({
68
- cwd: opts.cwd,
69
- rootDir: opts.rootDir,
70
- env: types_1.Env.development,
71
- entry: opts.entry,
72
- userConfig: opts.config,
73
- babelPreset: opts.babelPreset,
74
- extraBabelPlugins: [
75
- ...(opts.beforeBabelPlugins || []),
76
- ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
77
- ...(opts.extraBabelPlugins || []),
78
- ],
79
- extraBabelPresets: [
80
- ...(opts.beforeBabelPresets || []),
81
- ...(opts.extraBabelPresets || []),
82
- ],
83
- extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
84
- chainWebpack: opts.chainWebpack,
85
- modifyWebpackConfig: opts.modifyWebpackConfig,
86
- hmr: true,
87
- analyze: process.env.ANALYZE,
88
- cache: opts.cache,
89
- });
90
- const depConfig = yield (0, config_1.getConfig)({
91
- cwd: opts.cwd,
92
- rootDir: opts.rootDir,
93
- env: types_1.Env.development,
94
- entry: opts.entry,
95
- userConfig: opts.config,
96
- hash: true,
97
- staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
98
- name: constants_1.MFSU_NAME,
99
- chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
100
- cache: {
101
- buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
102
- cacheDirectory: (0, path_1.join)(opts.rootDir || 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
+ });
103
55
  },
104
56
  });
105
- (_g = webpackConfig.resolve).alias || (_g.alias = {});
106
- // TODO: REMOVE ME
107
- ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
108
- // @ts-ignore
109
- webpackConfig.resolve.alias[dep] = require.resolve(dep);
110
- });
111
- yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
112
- config: webpackConfig,
113
- depConfig: depConfig,
114
- }));
115
- yield (0, server_1.createServer)({
116
- webpackConfig,
117
- userConfig: opts.config,
118
- cwd: opts.cwd,
119
- beforeMiddlewares: [
120
- ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
121
- ...(opts.beforeMiddlewares || []),
122
- ],
123
- port: opts.port,
124
- host: opts.host,
125
- afterMiddlewares: [...(opts.afterMiddlewares || [])],
126
- onDevCompileDone: opts.onDevCompileDone,
127
- onProgress: opts.onProgress,
128
- });
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,
129
132
  });
130
133
  }
131
134
  exports.dev = dev;
@@ -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);
@@ -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,34 +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 ? !!devtool : this.options.sourcemap;
42
- const assets = compilation.getAssets().filter((asset) => {
43
- return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
44
- });
45
- yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
46
- const { source, map } = asset.source.sourceAndMap();
47
- const sourceAsString = source.toString();
48
- const result = yield (0, esbuild_1.transform)(sourceAsString, {
49
- loader: 'css',
50
- sourcemap,
51
- sourcefile: asset.name,
52
- minify: true,
53
- });
54
- compilation.updateAsset(asset.name,
55
- // @ts-ignore
56
- sourcemap
57
- ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
58
- : new webpack_sources_1.RawSource(result.code), Object.assign(Object.assign({}, asset.info), { minimized: true }));
59
- })));
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);
60
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
+ }));
61
50
  }
62
51
  }
63
52
  exports.default = ESBuildCSSMinifyPlugin;
@@ -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
  exports.ParcelCSSMinifyPlugin = void 0;
13
4
  const utils_1 = require("@umijs/utils");
@@ -35,7 +26,7 @@ class ParcelCSSMinifyPlugin {
35
26
  // @ts-ignore
36
27
  stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
37
28
  additionalAssets: true,
38
- }, () => __awaiter(this, void 0, void 0, function* () { return yield this.transformAssets(compilation); }));
29
+ }, async () => await this.transformAssets(compilation));
39
30
  compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
40
31
  statsPrinter.hooks.print
41
32
  .for('asset.info.minimized')
@@ -47,29 +38,36 @@ class ParcelCSSMinifyPlugin {
47
38
  });
48
39
  });
49
40
  }
50
- transformAssets(compilation) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const { options: { devtool }, } = compilation.compiler;
53
- const sourcemap = this.options.sourceMap === undefined
54
- ? (devtool && devtool.includes('source-map'))
55
- : this.options.sourceMap;
56
- const assets = compilation.getAssets().filter((asset) => {
57
- return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
58
- });
59
- yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
60
- const { source, map } = asset.source.sourceAndMap();
61
- const sourceAsString = source.toString();
62
- const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
63
- const { transform } = (0, utils_1.importLazy)('@parcel/css');
64
- const result = yield transform(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
65
- const codeString = result.code.toString();
66
- compilation.updateAsset(asset.name,
67
- // @ts-ignore
68
- sourcemap
69
- ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
70
- : new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
71
- })));
41
+ async transformAssets(compilation) {
42
+ const { options: { devtool }, } = compilation.compiler;
43
+ const sourcemap = this.options.sourceMap === undefined
44
+ ? (devtool && devtool.includes('source-map'))
45
+ : this.options.sourceMap;
46
+ const assets = compilation.getAssets().filter((asset) => {
47
+ return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
72
48
  });
49
+ await Promise.all(assets.map(async (asset) => {
50
+ const { source, map } = asset.source.sourceAndMap();
51
+ const sourceAsString = source.toString();
52
+ const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
53
+ const { transform } = (0, utils_1.importLazy)('@parcel/css');
54
+ const result = await transform({
55
+ filename: asset.name,
56
+ code,
57
+ minify: true,
58
+ sourceMap: sourcemap,
59
+ ...this.options,
60
+ });
61
+ const codeString = result.code.toString();
62
+ compilation.updateAsset(asset.name,
63
+ // @ts-ignore
64
+ sourcemap
65
+ ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
66
+ : new webpack_sources_1.RawSource(codeString), {
67
+ ...asset.info,
68
+ minimized: true,
69
+ });
70
+ }));
73
71
  }
74
72
  }
75
73
  exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
@@ -11,7 +11,7 @@ class RuntimePublicPathPlugin {
11
11
  // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
12
  if (module.constructor.name === 'PublicPathRuntimeModule') {
13
13
  // @ts-ignore
14
- module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
14
+ module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
15
15
  }
16
16
  });
17
17
  });
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,6 +52,7 @@ 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(),
@@ -13,5 +13,5 @@ interface IOpts {
13
13
  onDevCompileDone?: Function;
14
14
  onProgress?: Function;
15
15
  }
16
- export declare function createServer(opts: IOpts): Promise<import("https").Server | http.Server | null>;
16
+ export declare function createServer(opts: IOpts): Promise<http.Server | import("https").Server | null>;
17
17
  export {};