@umijs/bundler-webpack 4.0.40 → 4.0.42

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.
package/dist/dev.js CHANGED
@@ -23,7 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
23
23
  var dev_exports = {};
24
24
  __export(dev_exports, {
25
25
  dev: () => dev,
26
- stripUndefined: () => stripUndefined
26
+ ensureSerializableValue: () => ensureSerializableValue
27
27
  });
28
28
  module.exports = __toCommonJS(dev_exports);
29
29
  var import_mfsu = require("@umijs/mfsu");
@@ -35,13 +35,13 @@ var import_config = require("./config/config");
35
35
  var import_constants = require("./constants");
36
36
  var import_server = require("./server/server");
37
37
  var import_types = require("./types");
38
- function stripUndefined(obj) {
39
- Object.keys(obj).forEach((key) => {
40
- if (obj[key] === void 0) {
41
- delete obj[key];
38
+ function ensureSerializableValue(obj) {
39
+ return JSON.parse(JSON.stringify(obj, (_key, value) => {
40
+ if (typeof value === "function") {
41
+ return value.toString();
42
42
  }
43
- });
44
- return obj;
43
+ return value;
44
+ }, 2));
45
45
  }
46
46
  async function dev(opts) {
47
47
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
@@ -49,9 +49,6 @@ async function dev(opts) {
49
49
  const enableMFSU = opts.config.mfsu !== false;
50
50
  let mfsu = null;
51
51
  if (enableMFSU) {
52
- if (opts.config.srcTranspiler === import_types.Transpiler.swc) {
53
- import_utils.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
54
- }
55
52
  mfsu = new import_mfsu.MFSU({
56
53
  strategy: opts.mfsuStrategy,
57
54
  include: opts.mfsuInclude || [],
@@ -70,7 +67,7 @@ async function dev(opts) {
70
67
  remoteAliases: (_g = opts.config.mfsu) == null ? void 0 : _g.remoteAliases,
71
68
  remoteName: (_h = opts.config.mfsu) == null ? void 0 : _h.remoteName,
72
69
  getCacheDependency() {
73
- return stripUndefined({
70
+ return ensureSerializableValue({
74
71
  version: require("../package.json").version,
75
72
  mfsu: opts.config.mfsu,
76
73
  alias: opts.config.alias,
@@ -168,5 +165,5 @@ async function dev(opts) {
168
165
  // Annotate the CommonJS export names for ESM import in node:
169
166
  0 && (module.exports = {
170
167
  dev,
171
- stripUndefined
168
+ ensureSerializableValue
172
169
  });
@@ -1,4 +1,4 @@
1
1
  import type { LoaderContext } from '../../compiled/webpack';
2
- import { SwcOptions } from '../types';
3
- declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string): void;
2
+ import { type SwcOptions } from '../types';
3
+ declare function swcLoader(this: LoaderContext<SwcOptions>, contents: string, inputSourceMap: string | Record<string, any>): void;
4
4
  export default swcLoader;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
17
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
21
 
19
22
  // src/loader/swc.ts
@@ -24,6 +27,7 @@ __export(swc_exports, {
24
27
  module.exports = __toCommonJS(swc_exports);
25
28
  var import_core = require("@swc/core");
26
29
  var import_types = require("../types");
30
+ var import_utils = require("@umijs/utils");
27
31
  function getBaseOpts({ filename }) {
28
32
  const isTSFile = filename.endsWith(".ts");
29
33
  const isTypeScript = isTSFile || filename.endsWith(".tsx");
@@ -54,20 +58,54 @@ function getBaseOpts({ filename }) {
54
58
  };
55
59
  return swcOpts;
56
60
  }
57
- function swcLoader(contents) {
61
+ function swcLoader(contents, inputSourceMap) {
58
62
  const callback = this.async();
59
63
  const loaderOpts = this.getOptions();
60
- const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
64
+ if (inputSourceMap && typeof inputSourceMap === "object") {
65
+ inputSourceMap = JSON.stringify(inputSourceMap);
66
+ }
67
+ const {
68
+ sync = false,
69
+ parseMap = false,
70
+ excludeFiles = [],
71
+ enableAutoCssModulesPlugin = false,
72
+ mergeConfigs,
73
+ ...otherOpts
74
+ } = loaderOpts;
61
75
  const filename = this.resourcePath;
62
- const swcOpts = {
76
+ const isSkip = excludeFiles.some((pattern) => {
77
+ if (typeof pattern === "string") {
78
+ return filename == pattern;
79
+ }
80
+ return pattern.test(filename);
81
+ });
82
+ if (isSkip) {
83
+ return callback(null, contents, parseMap ? JSON.parse(inputSourceMap) : inputSourceMap);
84
+ }
85
+ let swcOpts = {
63
86
  ...getBaseOpts({
64
87
  filename
65
88
  }),
66
89
  filename,
67
- sourceMaps: this.sourceMap,
68
90
  sourceFileName: filename,
91
+ sourceMaps: this.sourceMap,
92
+ ...inputSourceMap ? {
93
+ inputSourceMap
94
+ } : {},
69
95
  ...otherOpts
70
96
  };
97
+ if (enableAutoCssModulesPlugin) {
98
+ swcOpts = (0, import_utils.deepmerge)(swcOpts, {
99
+ jsc: {
100
+ experimental: {
101
+ plugins: [[require.resolve("swc-plugin-auto-css-modules"), {}]]
102
+ }
103
+ }
104
+ });
105
+ }
106
+ if (mergeConfigs) {
107
+ swcOpts = (0, import_utils.deepmerge)(swcOpts, mergeConfigs);
108
+ }
71
109
  try {
72
110
  if (sync) {
73
111
  const output = (0, import_core.transformSync)(contents, swcOpts);
package/dist/schema.js CHANGED
@@ -112,6 +112,10 @@ function getSchemas() {
112
112
  runtimePublicPath: (Joi) => Joi.object(),
113
113
  sassLoader: (Joi) => Joi.object(),
114
114
  srcTranspiler: (Joi) => Joi.string().valid(import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc, import_types.Transpiler.none),
115
+ srcTranspilerOptions: (Joi) => Joi.object({
116
+ esbuild: Joi.object(),
117
+ swc: Joi.object()
118
+ }),
115
119
  styleLoader: (Joi) => Joi.object(),
116
120
  svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
117
121
  svgr: (Joi) => Joi.object(),
@@ -7,7 +7,11 @@ declare class AutoCSSModule extends Visitor {
7
7
  * visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
8
8
  * @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
9
9
  */
10
- visitModuleItem(n: ModuleItem): ImportDeclaration | import("@swc/core").ExportDeclaration | import("@swc/core").ExportNamedDeclaration | import("@swc/core").ExportDefaultDeclaration | import("@swc/core").ExportDefaultExpression | import("@swc/core").ExportAllDeclaration | import("@swc/core").TsImportEqualsDeclaration | import("@swc/core").TsExportAssignment | import("@swc/core").TsNamespaceExportDeclaration | import("@swc/core").ExpressionStatement | import("@swc/core").BlockStatement | import("@swc/core").EmptyStatement | import("@swc/core").DebuggerStatement | import("@swc/core").WithStatement | import("@swc/core").ReturnStatement | import("@swc/core").LabeledStatement | import("@swc/core").BreakStatement | import("@swc/core").ContinueStatement | import("@swc/core").IfStatement | import("@swc/core").SwitchStatement | import("@swc/core").ThrowStatement | import("@swc/core").TryStatement | import("@swc/core").WhileStatement | import("@swc/core").DoWhileStatement | import("@swc/core").ForStatement | import("@swc/core").ForInStatement | import("@swc/core").ForOfStatement | import("@swc/core").ClassDeclaration | import("@swc/core").FunctionDeclaration | import("@swc/core").VariableDeclaration | import("@swc/core").TsInterfaceDeclaration | import("@swc/core").TsTypeAliasDeclaration | import("@swc/core").TsEnumDeclaration | import("@swc/core").TsModuleDeclaration;
10
+ visitModuleItem(n: ModuleItem): ImportDeclaration | import("@swc/core").ExportDeclaration | import("@swc/core").ExportNamedDeclaration | import("@swc/core").ExportDefaultDeclaration | import("@swc/core").ExportDefaultExpression | import("@swc/core").ExportAllDeclaration | import("@swc/core").TsImportEqualsDeclaration | import("@swc/core").TsExportAssignment | import("@swc/core").TsNamespaceExportDeclaration | import("@swc/core").BlockStatement | import("@swc/core").EmptyStatement | import("@swc/core").DebuggerStatement | import("@swc/core").WithStatement | import("@swc/core").ReturnStatement | import("@swc/core").LabeledStatement | import("@swc/core").BreakStatement | import("@swc/core").ContinueStatement | import("@swc/core").IfStatement | import("@swc/core").SwitchStatement | import("@swc/core").ThrowStatement | import("@swc/core").TryStatement | import("@swc/core").WhileStatement | import("@swc/core").DoWhileStatement | import("@swc/core").ForStatement | import("@swc/core").ForInStatement | import("@swc/core").ForOfStatement | import("@swc/core").ClassDeclaration | import("@swc/core").FunctionDeclaration | import("@swc/core").VariableDeclaration | import("@swc/core").TsInterfaceDeclaration | import("@swc/core").TsTypeAliasDeclaration | import("@swc/core").TsEnumDeclaration | import("@swc/core").TsModuleDeclaration | import("@swc/core").ExpressionStatement;
11
11
  visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
12
12
  }
13
+ /**
14
+ * @deprecated Swc will not support js plugin in the future.
15
+ * See https://github.com/swc-project/website/commit/fde42ad5371c1a16ca9729fe17bcfd3489841ac1
16
+ */
13
17
  export default AutoCSSModule;
package/dist/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { Config as SwcConfig } from '@swc/core';
1
+ import type { Options as SwcConfig } from '@swc/core';
2
2
  import type { HttpsServerOptions, ProxyOptions } from '@umijs/bundler-utils';
3
3
  import webpack, { Configuration } from '../compiled/webpack';
4
4
  import Config from '../compiled/webpack-5-chain';
5
+ import type { TransformOptions as EsbuildOptions } from '@umijs/bundler-utils/compiled/esbuild';
5
6
  export declare enum Env {
6
7
  development = "development",
7
8
  production = "production"
@@ -103,6 +104,7 @@ export interface IConfig {
103
104
  [key: string]: any;
104
105
  };
105
106
  srcTranspiler?: `${Transpiler}`;
107
+ srcTranspilerOptions?: ISrcTranspilerOpts;
106
108
  styleLoader?: {
107
109
  [key: string]: any;
108
110
  };
@@ -120,8 +122,17 @@ export interface IConfig {
120
122
  analyze?: Record<string, any>;
121
123
  [key: string]: any;
122
124
  }
123
- export interface SwcOptions extends SwcConfig {
125
+ export interface ISrcTranspilerOpts {
126
+ swc?: Partial<SwcConfig>;
127
+ esbuild?: Partial<EsbuildOptions>;
128
+ }
129
+ export interface ISwcPluginOpts {
130
+ enableAutoCssModulesPlugin?: boolean;
131
+ }
132
+ export interface SwcOptions extends SwcConfig, ISwcPluginOpts {
124
133
  sync?: boolean;
125
134
  parseMap?: boolean;
135
+ excludeFiles?: Array<string | RegExp>;
136
+ mergeConfigs?: Partial<SwcConfig>;
126
137
  }
127
138
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.40",
3
+ "version": "4.0.42",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -34,11 +34,11 @@
34
34
  "@svgr/plugin-jsx": "^6.2.1",
35
35
  "@svgr/plugin-svgo": "^6.2.0",
36
36
  "@types/hapi__joi": "17.1.8",
37
- "@umijs/babel-preset-umi": "4.0.40",
38
- "@umijs/bundler-utils": "4.0.40",
37
+ "@umijs/babel-preset-umi": "4.0.42",
38
+ "@umijs/bundler-utils": "4.0.42",
39
39
  "@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
40
- "@umijs/mfsu": "4.0.40",
41
- "@umijs/utils": "4.0.40",
40
+ "@umijs/mfsu": "4.0.42",
41
+ "@umijs/utils": "4.0.42",
42
42
  "cors": "^2.8.5",
43
43
  "css-loader": "6.7.1",
44
44
  "es5-imcompatible-versions": "^0.1.73",
@@ -51,11 +51,11 @@
51
51
  "react-refresh": "0.14.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@swc/core": "1.2.165",
54
+ "@swc/core": "1.3.24",
55
55
  "@types/cors": "^2.8.12",
56
56
  "@types/webpack-sources": "3.2.0",
57
57
  "@types/ws": "8.5.3",
58
- "autoprefixer": "10.4.4",
58
+ "autoprefixer": "10.4.13",
59
59
  "babel-loader": "8.2.4",
60
60
  "compression": "1.7.4",
61
61
  "connect-history-api-fallback": "1.6.0",
@@ -72,6 +72,7 @@
72
72
  "speed-measure-webpack-plugin": "1.5.0",
73
73
  "style-loader": "3.3.1",
74
74
  "svgo-loader": "3.0.0",
75
+ "swc-plugin-auto-css-modules": "1.3.0",
75
76
  "terser": "5.12.1",
76
77
  "terser-webpack-plugin": "5.3.1",
77
78
  "url-loader": "4.1.1",
@@ -81,6 +82,7 @@
81
82
  "webpack-dev-middleware": "5.3.3",
82
83
  "webpack-manifest-plugin": "5.0.0",
83
84
  "webpack-sources": "3.2.3",
85
+ "webpackbar": "5.0.2",
84
86
  "ws": "8.5.0"
85
87
  },
86
88
  "publishConfig": {
@@ -117,6 +119,7 @@
117
119
  "webpack-dev-middleware",
118
120
  "webpack-manifest-plugin",
119
121
  "webpack-sources",
122
+ "webpackbar",
120
123
  "ws",
121
124
  "./bundles/webpack/bundle"
122
125
  ],