@umijs/bundler-webpack 4.0.0-canary.20220323.1 → 4.0.0-canary.20220412.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 (36) hide show
  1. package/client/client/client.js +57 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
  4. package/compiled/copy-webpack-plugin/index.js +12 -12
  5. package/compiled/cssnano/index.js +6 -6
  6. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  7. package/compiled/react-refresh/LICENSE +21 -0
  8. package/compiled/react-refresh/index.js +9 -7
  9. package/compiled/react-refresh/package.json +1 -0
  10. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  11. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  12. package/compiled/webpack/index.js +4430 -2883
  13. package/dist/client/client.js +10 -3
  14. package/dist/config/compressPlugin.js +9 -1
  15. package/dist/config/config.js +3 -0
  16. package/dist/config/nodePolyfill.js +1 -1
  17. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  18. package/dist/config/nodePrefixPlugin.js +25 -0
  19. package/dist/constants.d.ts +1 -0
  20. package/dist/constants.js +7 -1
  21. package/dist/dev.d.ts +2 -0
  22. package/dist/dev.js +7 -0
  23. package/dist/schema.js +1 -0
  24. package/dist/server/https.d.ts +5 -0
  25. package/dist/server/https.js +73 -0
  26. package/dist/server/server.d.ts +2 -1
  27. package/dist/server/server.js +32 -8
  28. package/dist/server/ws.d.ts +3 -2
  29. package/dist/swcPlugins/autoCSSModules.js +3 -1
  30. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  31. package/dist/swcPlugins/changeImportFromString.js +10 -0
  32. package/dist/swcPlugins/lockCoreJS.js +3 -2
  33. package/dist/types.d.ts +6 -0
  34. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  35. package/dist/utils/getEsBuildTarget.js +12 -0
  36. package/package.json +13 -11
@@ -41,14 +41,21 @@ const ErrorOverlay = __importStar(require("react-error-overlay"));
41
41
  const constants_1 = require("../constants");
42
42
  const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
43
43
  console.log('[webpack] connecting...');
44
+ function getSocketHost() {
45
+ let l = location;
46
+ if (process.env.SOCKET_SERVER) {
47
+ l = new URL(process.env.SOCKET_SERVER);
48
+ }
49
+ const host = l.host;
50
+ const isHttps = l.protocol === 'https:';
51
+ return `${isHttps ? 'wss' : 'ws'}://${host}`;
52
+ }
44
53
  let pingTimer = null;
45
- const host = location.host;
46
- const wsUrl = `ws://${host}`;
47
54
  let isFirstCompilation = true;
48
55
  let mostRecentCompilationHash = null;
49
56
  let hasCompileErrors = false;
50
57
  let hadRuntimeError = false;
51
- const socket = new WebSocket(wsUrl, 'webpack-hmr');
58
+ const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
52
59
  socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
53
60
  data = JSON.parse(data);
54
61
  if (data.type === 'connected') {
@@ -19,6 +19,7 @@ const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-w
19
19
  const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
20
20
  const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
21
21
  const types_1 = require("../types");
22
+ const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
22
23
  function addCompressPlugin(opts) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
25
  const { config, userConfig, env } = opts;
@@ -32,8 +33,14 @@ function addCompressPlugin(opts) {
32
33
  }
33
34
  config.optimization.minimize(true);
34
35
  let minify;
36
+ let terserOptions;
35
37
  if (jsMinifier === types_1.JSMinifier.esbuild) {
36
38
  minify = terser_webpack_plugin_1.default.esbuildMinify;
39
+ terserOptions = {
40
+ target: (0, getEsBuildTarget_1.getEsBuildTarget)({
41
+ targets: userConfig.targets || {},
42
+ }),
43
+ };
37
44
  }
38
45
  else if (jsMinifier === types_1.JSMinifier.terser) {
39
46
  minify = terser_webpack_plugin_1.default.terserMinify;
@@ -47,11 +54,12 @@ function addCompressPlugin(opts) {
47
54
  else if (jsMinifier !== types_1.JSMinifier.none) {
48
55
  throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
49
56
  }
57
+ terserOptions = Object.assign(Object.assign({}, terserOptions), userConfig.jsMinifierOptions);
50
58
  if (jsMinifier !== types_1.JSMinifier.none) {
51
59
  config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
52
60
  {
53
61
  minify,
54
- terserOptions: userConfig.jsMinifierOptions,
62
+ terserOptions,
55
63
  },
56
64
  ]);
57
65
  }
@@ -35,6 +35,7 @@ const javaScriptRules_1 = require("./javaScriptRules");
35
35
  const manifestPlugin_1 = require("./manifestPlugin");
36
36
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
37
37
  const nodePolyfill_1 = require("./nodePolyfill");
38
+ const nodePrefixPlugin_1 = require("./nodePrefixPlugin");
38
39
  const progressPlugin_1 = require("./progressPlugin");
39
40
  const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
40
41
  const svgRules_1 = require("./svgRules");
@@ -153,6 +154,8 @@ function getConfig(opts) {
153
154
  // await applyPurgeCSSWebpackPlugin(applyOpts);
154
155
  // handle HarmonyLinkingError
155
156
  yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
157
+ // remove node: prefix
158
+ yield (0, nodePrefixPlugin_1.addNodePrefixPlugin)(applyOpts);
156
159
  // runtimePublicPath
157
160
  if (userConfig.runtimePublicPath) {
158
161
  config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
@@ -14,12 +14,12 @@ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
14
  function addNodePolyfill(opts) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  const { config } = opts;
17
- const nodeLibs = require('node-libs-browser');
18
17
  config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
19
18
  {
20
19
  Buffer: ['buffer', 'Buffer'],
21
20
  },
22
21
  ]);
22
+ const nodeLibs = require('node-libs-browser');
23
23
  config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
24
24
  if (nodeLibs[key]) {
25
25
  memo[key] = nodeLibs[key];
@@ -0,0 +1,11 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export declare function addNodePrefixPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addNodePrefixPlugin = void 0;
13
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
+ function addNodePrefixPlugin(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { config } = opts;
17
+ config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
18
+ /^node:/,
19
+ (resource) => {
20
+ resource.request = resource.request.replace(/^node:/, '');
21
+ },
22
+ ]);
23
+ });
24
+ }
25
+ exports.addNodePrefixPlugin = addNodePrefixPlugin;
@@ -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;
package/dist/dev.js CHANGED
@@ -41,11 +41,17 @@ function dev(opts) {
41
41
  runtimePublicPath: opts.config.runtimePublicPath,
42
42
  tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
43
43
  (0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
44
+ onMFSUProgress: opts.onMFSUProgress,
44
45
  getCacheDependency() {
45
46
  var _a;
46
47
  return {
47
48
  version: require('../package.json').version,
48
49
  esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
50
+ alias: opts.config.alias,
51
+ externals: opts.config.externals,
52
+ theme: opts.config.theme,
53
+ runtimePublicPath: !!opts.config.runtimePublicPath,
54
+ publicPath: opts.config.publicPath,
49
55
  };
50
56
  },
51
57
  });
@@ -108,6 +114,7 @@ function dev(opts) {
108
114
  host: opts.host,
109
115
  afterMiddlewares: [...(opts.afterMiddlewares || [])],
110
116
  onDevCompileDone: opts.onDevCompileDone,
117
+ onProgress: opts.onProgress,
111
118
  });
112
119
  });
113
120
  }
package/dist/schema.js CHANGED
@@ -46,6 +46,7 @@ function getSchemas() {
46
46
  fastRefresh: (Joi) => Joi.boolean(),
47
47
  forkTSChecker: (Joi) => Joi.object(),
48
48
  hash: (Joi) => Joi.boolean(),
49
+ https: (Joi) => Joi.object(),
49
50
  ignoreMomentLocale: (Joi) => Joi.boolean(),
50
51
  inlineLimit: (Joi) => Joi.number(),
51
52
  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),
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import { RequestListener } from 'http';
3
+ import https from 'https';
4
+ import { HttpsParams } from '../types';
5
+ export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsParams): Promise<https.Server>;
@@ -0,0 +1,73 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createHttpsServer = void 0;
16
+ const utils_1 = require("@umijs/utils");
17
+ const fs_1 = require("fs");
18
+ const https_1 = __importDefault(require("https"));
19
+ const path_1 = require("path");
20
+ const defaultHttpsHosts = ['localhost', '127.0.0.1'];
21
+ function createHttpsServer(app, httpsConfig) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ utils_1.logger.wait('[HTTPS] Starting service in https mode...');
24
+ // Check if mkcert is installed
25
+ try {
26
+ yield utils_1.execa.execa('mkcert', ['--version']);
27
+ }
28
+ catch (e) {
29
+ utils_1.logger.error('[HTTPS] The mkcert has not been installed.');
30
+ utils_1.logger.info('[HTTPS] Please follow the guide to install manually.');
31
+ switch (process.platform) {
32
+ case 'darwin':
33
+ console.log(utils_1.chalk.green('$ brew install mkcert'));
34
+ console.log(utils_1.chalk.gray('# If you use firefox, please install nss.'));
35
+ console.log(utils_1.chalk.green('$ brew install nss'));
36
+ console.log(utils_1.chalk.green('$ mkcert -install'));
37
+ break;
38
+ case 'win32':
39
+ console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#windows'));
40
+ break;
41
+ case 'linux':
42
+ console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#linux'));
43
+ break;
44
+ default:
45
+ break;
46
+ }
47
+ throw new Error(`[HTTPS] mkcert not found.`);
48
+ }
49
+ let { key, cert, hosts } = httpsConfig;
50
+ hosts = hosts || defaultHttpsHosts;
51
+ if (!key || !cert) {
52
+ key = (0, path_1.join)(__dirname, 'umi.key.pem');
53
+ cert = (0, path_1.join)(__dirname, 'umi.pem');
54
+ }
55
+ // Generate cert and key files if they are not exist.
56
+ if (!(0, fs_1.existsSync)(key) || !(0, fs_1.existsSync)(cert)) {
57
+ utils_1.logger.wait('[HTTPS] Generating cert and key files...');
58
+ yield utils_1.execa.execa('mkcert', [
59
+ '-cert-file',
60
+ cert,
61
+ '-key-file',
62
+ key,
63
+ ...hosts,
64
+ ]);
65
+ }
66
+ // Create server
67
+ return https_1.default.createServer({
68
+ key: (0, fs_1.readFileSync)(key, 'utf-8'),
69
+ cert: (0, fs_1.readFileSync)(cert, 'utf-8'),
70
+ }, app);
71
+ });
72
+ }
73
+ exports.createHttpsServer = createHttpsServer;
@@ -11,6 +11,7 @@ interface IOpts {
11
11
  beforeMiddlewares?: any[];
12
12
  afterMiddlewares?: any[];
13
13
  onDevCompileDone?: Function;
14
+ onProgress?: Function;
14
15
  }
15
- export declare function createServer(opts: IOpts): Promise<http.Server>;
16
+ export declare function createServer(opts: IOpts): Promise<import("https").Server | http.Server | null>;
16
17
  export {};
@@ -21,6 +21,7 @@ const fs_1 = require("fs");
21
21
  const http_1 = __importDefault(require("http"));
22
22
  const path_1 = require("path");
23
23
  const constants_1 = require("../constants");
24
+ const https_1 = require("./https");
24
25
  const ws_1 = require("./ws");
25
26
  function createServer(opts) {
26
27
  return __awaiter(this, void 0, void 0, function* () {
@@ -42,7 +43,7 @@ function createServer(opts) {
42
43
  // cros
43
44
  app.use((_req, res, next) => {
44
45
  res.header('Access-Control-Allow-Origin', '*');
45
- res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
46
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
46
47
  res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
47
48
  next();
48
49
  });
@@ -55,17 +56,35 @@ function createServer(opts) {
55
56
  app.use((req, res, next) => {
56
57
  if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
57
58
  res.setHeader('Content-Type', 'application/javascript');
58
- res.send((0, fs_1.readFileSync)((0, path_1.join)(opts.cwd, 'umi.js'), 'utf-8'));
59
+ (0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
59
60
  }
60
61
  else {
61
62
  next();
62
63
  }
63
64
  });
64
65
  // webpack dev middleware
65
- const compiler = (0, webpack_1.default)(Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig]);
66
+ const configs = Array.isArray(webpackConfig)
67
+ ? webpackConfig
68
+ : [webpackConfig];
69
+ const progresses = [];
70
+ if (opts.onProgress) {
71
+ configs.forEach((config) => {
72
+ const progress = {
73
+ percent: 0,
74
+ status: 'waiting',
75
+ };
76
+ progresses.push(progress);
77
+ config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
78
+ progress.percent = percent;
79
+ progress.status = msg;
80
+ opts.onProgress({ progresses });
81
+ }));
82
+ });
83
+ }
84
+ const compiler = (0, webpack_1.default)(configs);
66
85
  const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
67
86
  const compilerMiddleware = webpackDevMiddleware(compiler, {
68
- publicPath: '/',
87
+ publicPath: userConfig.publicPath || '/',
69
88
  writeToDisk: userConfig.writeToDisk,
70
89
  stats: 'none',
71
90
  // watchOptions: { ignored }
@@ -165,24 +184,29 @@ function createServer(opts) {
165
184
  res.set('Content-Type', 'text/html');
166
185
  const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
167
186
  if ((0, fs_1.existsSync)(htmlPath)) {
168
- const html = (0, fs_1.readFileSync)(htmlPath, 'utf-8');
169
- res.send(html);
187
+ (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
170
188
  }
171
189
  else {
172
190
  next();
173
191
  }
174
192
  });
175
- const server = http_1.default.createServer(app);
193
+ const server = userConfig.https
194
+ ? yield (0, https_1.createHttpsServer)(app, userConfig.https)
195
+ : http_1.default.createServer(app);
196
+ if (!server) {
197
+ return null;
198
+ }
176
199
  const ws = (0, ws_1.createWebSocketServer)(server);
177
200
  ws.wss.on('connection', (socket) => {
178
201
  if (stats) {
179
202
  sendStats(getStats(stats), false, socket);
180
203
  }
181
204
  });
205
+ const protocol = userConfig.https ? 'https:' : 'http:';
182
206
  const port = opts.port || 8000;
183
207
  server.listen(port, () => {
184
208
  const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
185
- utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`http://${host}:${port}`)}`);
209
+ utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
186
210
  });
187
211
  return server;
188
212
  });
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { Server } from 'http';
2
+ import { Server as HttpServer } from 'http';
3
+ import { Server as HttpsServer } from 'https';
3
4
  import WebSocket from '../../compiled/ws';
4
- export declare function createWebSocketServer(server: Server): {
5
+ export declare function createWebSocketServer(server: HttpServer | HttpsServer): {
5
6
  send(message: string): void;
6
7
  wss: WebSocket.Server;
7
8
  close(): void;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
7
7
  const utils_1 = require("@umijs/utils");
8
+ const changeImportFromString_1 = require("./changeImportFromString");
8
9
  class AutoCSSModule extends Visitor_1.default {
9
10
  visitTsType(expression) {
10
11
  return expression;
@@ -24,7 +25,8 @@ class AutoCSSModule extends Visitor_1.default {
24
25
  const { specifiers, source } = expression;
25
26
  const { value } = source;
26
27
  if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
27
- return Object.assign(Object.assign({}, expression), { source: Object.assign(Object.assign({}, source), { value: `${value}?modules` }) });
28
+ const newImportFrom = `${value}?modules`;
29
+ (0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
28
30
  }
29
31
  return expression;
30
32
  }
@@ -0,0 +1,2 @@
1
+ import type { ImportDeclaration } from '@swc/core';
2
+ export declare const changeImportFromString: (e: ImportDeclaration, v: string) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.changeImportFromString = void 0;
4
+ const changeImportFromString = (e, v) => {
5
+ e.source.value = v;
6
+ // sync change to `raw`
7
+ // https://github.com/swc-project/swc/issues/4128
8
+ e.source.raw = `'${v}'`;
9
+ };
10
+ exports.changeImportFromString = changeImportFromString;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
7
7
  const utils_1 = require("@umijs/utils");
8
8
  const path_1 = require("path");
9
+ const changeImportFromString_1 = require("./changeImportFromString");
9
10
  function addLastSlash(path) {
10
11
  return path.endsWith('/') ? path : `${path}/`;
11
12
  }
@@ -14,8 +15,8 @@ class LockCoreJS extends Visitor_1.default {
14
15
  const { source } = expression;
15
16
  let { value, type } = source;
16
17
  if (type === 'StringLiteral' && value.startsWith('core-js/')) {
17
- value = value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
18
- return Object.assign(Object.assign({}, expression), { source: Object.assign(Object.assign({}, source), { value }) });
18
+ const newValue = value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
19
+ (0, changeImportFromString_1.changeImportFromString)(expression, newValue);
19
20
  }
20
21
  return expression;
21
22
  }
package/dist/types.d.ts CHANGED
@@ -41,6 +41,11 @@ export interface DeadCodeParams {
41
41
  detectUnusedExport?: boolean;
42
42
  context?: string;
43
43
  }
44
+ export interface HttpsParams {
45
+ key?: string;
46
+ cert?: string;
47
+ hosts?: string[];
48
+ }
44
49
  export interface IConfig {
45
50
  alias?: Record<string, string>;
46
51
  autoCSSModules?: boolean;
@@ -63,6 +68,7 @@ export interface IConfig {
63
68
  depTranspiler?: Transpiler;
64
69
  devtool?: Config.DevTool;
65
70
  deadCode?: DeadCodeParams;
71
+ https?: HttpsParams;
66
72
  externals?: WebpackConfig['externals'];
67
73
  esm?: {
68
74
  [key: string]: any;
@@ -0,0 +1,5 @@
1
+ interface IOpts {
2
+ targets: Record<string, any>;
3
+ }
4
+ export declare function getEsBuildTarget({ targets }: IOpts): string[];
5
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEsBuildTarget = void 0;
4
+ const constants_1 = require("../constants");
5
+ function getEsBuildTarget({ targets }) {
6
+ return Object.keys(targets)
7
+ .filter((key) => constants_1.DEFAULT_ESBUILD_TARGET_KEYS.includes(key))
8
+ .map((key) => {
9
+ return `${key}${targets[key] === true ? '0' : targets[key]}`;
10
+ });
11
+ }
12
+ exports.getEsBuildTarget = getEsBuildTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-canary.20220323.1",
3
+ "version": "4.0.0-canary.20220412.2",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -29,15 +29,16 @@
29
29
  "test": "jest -c ../../jest.turbo.config.ts"
30
30
  },
31
31
  "dependencies": {
32
- "@parcel/css": "1.7.2",
33
- "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
32
+ "@parcel/css": "1.8.1",
33
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
34
34
  "@svgr/core": "6.2.1",
35
35
  "@svgr/plugin-jsx": "^6.2.1",
36
36
  "@svgr/plugin-svgo": "^6.2.0",
37
37
  "@types/hapi__joi": "17.1.8",
38
- "@umijs/babel-preset-umi": "4.0.0-canary.20220323.1",
39
- "@umijs/mfsu": "4.0.0-canary.20220323.1",
40
- "@umijs/utils": "4.0.0-canary.20220323.1",
38
+ "@umijs/babel-preset-umi": "4.0.0-canary.20220412.2",
39
+ "@umijs/bundler-utils": "4.0.0-canary.20220412.2",
40
+ "@umijs/mfsu": "4.0.0-canary.20220412.2",
41
+ "@umijs/utils": "4.0.0-canary.20220412.2",
41
42
  "css-loader": "6.7.1",
42
43
  "es5-imcompatible-versions": "^0.1.73",
43
44
  "jest-worker": "27.5.1",
@@ -47,7 +48,7 @@
47
48
  "react-error-overlay": "6.0.9"
48
49
  },
49
50
  "devDependencies": {
50
- "@swc/core": "1.2.157",
51
+ "@swc/core": "1.2.165",
51
52
  "@types/webpack-sources": "3.2.0",
52
53
  "@types/ws": "8.5.3",
53
54
  "autoprefixer": "10.4.4",
@@ -56,15 +57,15 @@
56
57
  "connect-history-api-fallback": "1.6.0",
57
58
  "copy-webpack-plugin": "10.2.4",
58
59
  "css-minimizer-webpack-plugin": "3.4.1",
59
- "cssnano": "5.1.5",
60
- "fork-ts-checker-webpack-plugin": "7.2.1",
60
+ "cssnano": "5.1.7",
61
+ "fork-ts-checker-webpack-plugin": "7.2.4",
61
62
  "http-proxy-middleware": "2.0.4",
62
63
  "less-loader": "10.2.0",
63
64
  "mini-css-extract-plugin": "2.6.0",
64
65
  "postcss-flexbugs-fixes": "5.0.2",
65
66
  "postcss-loader": "6.2.1",
66
67
  "purgecss-webpack-plugin": "4.1.3",
67
- "react-refresh": "0.11.0",
68
+ "react-refresh": "0.12.0",
68
69
  "sass-loader": "12.6.0",
69
70
  "schema-utils": "4.0.0",
70
71
  "speed-measure-webpack-plugin": "1.5.0",
@@ -74,7 +75,7 @@
74
75
  "terser": "5.12.1",
75
76
  "terser-webpack-plugin": "5.3.1",
76
77
  "url-loader": "4.1.1",
77
- "webpack": "5.70.0",
78
+ "webpack": "5.72.0",
78
79
  "webpack-5-chain": "8.0.0",
79
80
  "webpack-bundle-analyzer": "4.5.0",
80
81
  "webpack-dev-middleware": "5.3.1",
@@ -174,6 +175,7 @@
174
175
  "postcss-flexbugs-fixes",
175
176
  "postcss-loader",
176
177
  "purgecss-webpack-plugin",
178
+ "react-refresh",
177
179
  "sass-loader",
178
180
  "speed-measure-webpack-plugin",
179
181
  "style-loader",