@umijs/bundler-utoopack 4.6.52 → 4.6.53

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/config.js CHANGED
@@ -98,6 +98,103 @@ function getModularizeImports(extraBabelPlugins) {
98
98
  {}
99
99
  );
100
100
  }
101
+ function getBabelPluginName(plugin) {
102
+ const name = Array.isArray(plugin) ? plugin[0] : plugin;
103
+ return typeof name === "string" ? name : "";
104
+ }
105
+ function isModularizeImportPlugin(plugin) {
106
+ return /^import$|babel-plugin-import/.test(getBabelPluginName(plugin));
107
+ }
108
+ function isEmotionBabelPlugin(plugin) {
109
+ const name = getBabelPluginName(plugin);
110
+ return name === "@emotion" || name.endsWith("@emotion/babel-plugin");
111
+ }
112
+ function getExtraBabelPlugins(opts) {
113
+ return [
114
+ ...opts.beforeBabelPlugins || [],
115
+ ...opts.extraBabelPlugins || [],
116
+ ...opts.config.extraBabelPlugins || []
117
+ ].filter(Boolean).filter(isSerializableBabelItem);
118
+ }
119
+ function getExtraBabelPresets(opts) {
120
+ return [
121
+ ...opts.beforeBabelPresets || [],
122
+ ...opts.extraBabelPresets || [],
123
+ ...opts.config.extraBabelPresets || []
124
+ ].filter(Boolean).filter(isSerializableBabelItem);
125
+ }
126
+ function dropUndefinedValues(value) {
127
+ if (Array.isArray(value)) {
128
+ return value.map(dropUndefinedValues);
129
+ }
130
+ if (value && typeof value === "object") {
131
+ return Object.fromEntries(
132
+ Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => [key, dropUndefinedValues(item)])
133
+ );
134
+ }
135
+ return value;
136
+ }
137
+ function isSerializableBabelItem(item) {
138
+ const normalized = dropUndefinedValues(item);
139
+ try {
140
+ return import_utils.lodash.isEqual(normalized, JSON.parse(JSON.stringify(normalized)));
141
+ } catch (e) {
142
+ return false;
143
+ }
144
+ }
145
+ function getExtraBabelModuleRules(opts) {
146
+ var _a;
147
+ if (((_a = opts.config.utoopack) == null ? void 0 : _a.babelLoader) !== true) {
148
+ return {};
149
+ }
150
+ const plugins = getExtraBabelPlugins(opts).filter((plugin) => {
151
+ return !isModularizeImportPlugin(plugin) && !isEmotionBabelPlugin(plugin);
152
+ });
153
+ const extraPresets = getExtraBabelPresets(opts);
154
+ if (!plugins.length && !extraPresets.length) {
155
+ return {};
156
+ }
157
+ const presets = [opts.babelPreset, ...extraPresets].filter(Boolean);
158
+ const rule = {
159
+ condition: {
160
+ all: [
161
+ { not: "foreign" },
162
+ {
163
+ not: {
164
+ path: /[\\/]src[\\/]\.umi(?:-[^\\/]*)?[\\/]/
165
+ }
166
+ }
167
+ ]
168
+ },
169
+ loaders: [
170
+ {
171
+ loader: require.resolve("@umijs/bundler-webpack/compiled/babel-loader"),
172
+ options: dropUndefinedValues({
173
+ sourceType: "unambiguous",
174
+ babelrc: false,
175
+ configFile: false,
176
+ cacheDirectory: false,
177
+ browserslistConfigFile: false,
178
+ targets: opts.config.targets,
179
+ customize: opts.config.babelLoaderCustomize,
180
+ presets,
181
+ plugins
182
+ })
183
+ }
184
+ ],
185
+ as: "*.js"
186
+ };
187
+ return {
188
+ module: {
189
+ rules: Object.fromEntries(
190
+ ["js", "mjs", "cjs", "jsx", "ts", "tsx"].map((ext) => [
191
+ `**/src/**/*.${ext}`,
192
+ rule
193
+ ])
194
+ )
195
+ }
196
+ };
197
+ }
101
198
  function getNormalizedAlias(alias, rootDir) {
102
199
  const newAlias = { ...alias };
103
200
  for (const [key, value] of Object.entries(newAlias)) {
@@ -251,7 +348,7 @@ function mergeExtraPostcssPlugins(postcssConfig, extraPlugins = []) {
251
348
  }, postcssConfig);
252
349
  }
253
350
  function getUserUtoopackConfig(utoopackConfig = {}) {
254
- return import_utils.lodash.omit(utoopackConfig, ["root"]);
351
+ return import_utils.lodash.omit(utoopackConfig, ["babelLoader", "root"]);
255
352
  }
256
353
  function getDefaultPersistentCaching() {
257
354
  return process.platform !== "win32";
@@ -338,9 +435,10 @@ async function getProdUtooPackConfig(opts) {
338
435
  define,
339
436
  nodePolyfill: true,
340
437
  mdx: !!mdx,
341
- externals: getNormalizedExternals(userExternals),
342
- ...getSvgModuleRules({ svgr, svgo, inlineLimit })
438
+ externals: getNormalizedExternals(userExternals)
343
439
  },
440
+ getExtraBabelModuleRules(opts),
441
+ getSvgModuleRules({ svgr, svgo, inlineLimit }),
344
442
  userUtoopackConfig
345
443
  )
346
444
  };
@@ -535,9 +633,10 @@ async function getDevUtooPackConfig(opts) {
535
633
  react: {
536
634
  absoluteSourceFilename: true
537
635
  }
538
- } : {},
539
- ...getSvgModuleRules({ svgr, svgo, inlineLimit })
636
+ } : {}
540
637
  },
638
+ getExtraBabelModuleRules(opts),
639
+ getSvgModuleRules({ svgr, svgo, inlineLimit }),
541
640
  userUtoopackConfig
542
641
  ),
543
642
  watch: {
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { IOpts as IConfigOpts } from '@umijs/bundler-webpack';
2
2
  import type { ConfigComplete } from '@utoo/pack';
3
3
  export declare type IUtoopackUserConfig = ConfigComplete & {
4
+ babelLoader?: boolean;
4
5
  root?: string;
5
6
  };
6
7
  export declare type IOpts = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.6.52",
3
+ "version": "4.6.53",
4
4
  "description": "@umijs/bundler-utoopack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "resolve-url-loader": "5.0.0",
21
21
  "sass": "1.54.0",
22
22
  "sass-loader": "13.2.0",
23
- "@umijs/bundler-utils": "4.6.52",
24
- "@umijs/bundler-webpack": "4.6.52"
23
+ "@umijs/bundler-utils": "4.6.53",
24
+ "@umijs/bundler-webpack": "4.6.53"
25
25
  },
26
26
  "devDependencies": {
27
27
  "father": "4.1.5"