@umijs/bundler-utoopack 4.5.2 → 4.6.0

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 (2) hide show
  1. package/dist/config.js +58 -13
  2. package/package.json +4 -7
package/dist/config.js CHANGED
@@ -50,7 +50,14 @@ function convertProcessEnvForUtoopack(webpackConfig) {
50
50
  function getModularizeImports(extraBabelPlugins) {
51
51
  return extraBabelPlugins.filter((p) => /^import$|babel-plugin-import/.test(p[0])).reduce(
52
52
  (acc, [_, v]) => {
53
- const { libraryName, libraryDirectory, style, ...rest } = v;
53
+ const {
54
+ libraryName,
55
+ libraryDirectory,
56
+ style,
57
+ camel2DashComponentName,
58
+ transformToDefaultImport,
59
+ ...rest
60
+ } = v;
54
61
  if (Object.keys(rest).length > 0) {
55
62
  throw new Error(
56
63
  `babel-plugin-import options ${Object.keys(
@@ -63,10 +70,15 @@ function getModularizeImports(extraBabelPlugins) {
63
70
  `babel-plugin-import style function is not supported in utoopack bundler`
64
71
  );
65
72
  }
73
+ let transformRule = "{{ kebabCase member }}";
74
+ if (camel2DashComponentName === false) {
75
+ transformRule = "{{ member }}";
76
+ }
77
+ const skipDefaultConversion = typeof transformToDefaultImport === "undefined" ? false : !Boolean(transformToDefaultImport);
66
78
  acc[libraryName] = {
67
- transform: `${libraryName}/${libraryDirectory}/{{ kebabCase member }}`,
79
+ transform: `${libraryName}/${libraryDirectory}/${transformRule}`,
68
80
  preventFullImport: false,
69
- skipDefaultConversion: false,
81
+ skipDefaultConversion,
70
82
  style: typeof style === "boolean" ? "style" : style
71
83
  };
72
84
  return acc;
@@ -76,12 +88,35 @@ function getModularizeImports(extraBabelPlugins) {
76
88
  }
77
89
  function getNormalizedAlias(alias, rootDir) {
78
90
  const newAlias = { ...alias };
79
- if (newAlias.react) {
80
- newAlias["react/*"] = `${newAlias.react}/*`;
91
+ const keysToExpand = ["react", "react-dom", "@", "@@"];
92
+ for (const key of keysToExpand) {
93
+ if (newAlias[key]) {
94
+ newAlias[`${key}/*`] = `${newAlias[key]}/*`;
95
+ }
81
96
  }
82
97
  newAlias[`${rootDir}/*`] = `${rootDir}/*`;
83
98
  return newAlias;
84
99
  }
100
+ function getNormalizedExternals(externals) {
101
+ return Object.entries(externals || {}).reduce(
102
+ (ret, [k, v]) => {
103
+ if (Array.isArray(v)) {
104
+ const [url, ...members] = v;
105
+ ret[k] = {
106
+ // ['antd', 'Button'] => `antd.Button`
107
+ root: members.join("."),
108
+ // `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
109
+ script: url.replace("script ", "")
110
+ };
111
+ } else if (typeof v === "string") {
112
+ ret[k] = v.replace(/^window(\s+|\.)/, "");
113
+ } else {
114
+ }
115
+ return ret;
116
+ },
117
+ {}
118
+ );
119
+ }
85
120
  async function getProdUtooPackConfig(opts) {
86
121
  var _a;
87
122
  const webpackConfig = await (0, import_bundler_webpack.getConfig)({
@@ -107,7 +142,7 @@ async function getProdUtooPackConfig(opts) {
107
142
  disableCopy: opts.disableCopy
108
143
  });
109
144
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
110
- ...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
145
+ ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
111
146
  compatMode: true
112
147
  });
113
148
  const extraBabelPlugins = [
@@ -116,7 +151,11 @@ async function getProdUtooPackConfig(opts) {
116
151
  ];
117
152
  const modularizeImports = getModularizeImports(extraBabelPlugins);
118
153
  const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
119
- const { publicPath, runtimePublicPath } = opts.config;
154
+ const {
155
+ publicPath,
156
+ runtimePublicPath,
157
+ externals: userExternals
158
+ } = opts.config;
120
159
  utooBundlerOpts = {
121
160
  ...utooBundlerOpts,
122
161
  config: import_utils.lodash.merge(
@@ -129,8 +168,6 @@ async function getProdUtooPackConfig(opts) {
129
168
  optimization: {
130
169
  modularizeImports,
131
170
  concatenateModules: true
132
- // minify: false,
133
- // moduleIds: 'named',
134
171
  },
135
172
  resolve: {
136
173
  alias: getNormalizedAlias(
@@ -149,7 +186,9 @@ async function getProdUtooPackConfig(opts) {
149
186
  // Override process.env for utoopack format
150
187
  define: {
151
188
  "process.env": JSON.stringify(processEnvForUtoopack)
152
- }
189
+ },
190
+ nodePolyfill: true,
191
+ externals: getNormalizedExternals(userExternals)
153
192
  },
154
193
  opts.config.utoopack || {}
155
194
  )
@@ -181,7 +220,7 @@ async function getDevUtooPackConfig(opts) {
181
220
  analyze: process.env.ANALYZE
182
221
  });
183
222
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
184
- ...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
223
+ ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
185
224
  compatMode: true
186
225
  });
187
226
  const extraBabelPlugins = [
@@ -190,7 +229,11 @@ async function getDevUtooPackConfig(opts) {
190
229
  ];
191
230
  const modularizeImports = getModularizeImports(extraBabelPlugins);
192
231
  const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
193
- const { publicPath, runtimePublicPath } = opts.config;
232
+ const {
233
+ publicPath,
234
+ runtimePublicPath,
235
+ externals: userExternals
236
+ } = opts.config;
194
237
  utooBundlerOpts = {
195
238
  ...utooBundlerOpts,
196
239
  config: import_utils.lodash.merge(
@@ -221,7 +264,9 @@ async function getDevUtooPackConfig(opts) {
221
264
  // Override process.env for utoopack format
222
265
  define: {
223
266
  "process.env": JSON.stringify(processEnvForUtoopack)
224
- }
267
+ },
268
+ nodePolyfill: true,
269
+ externals: getNormalizedExternals(userExternals)
225
270
  },
226
271
  opts.config.utoopack || {}
227
272
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.5.2",
3
+ "version": "4.6.0",
4
4
  "description": "@umijs/bundler-utoopack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,21 +8,18 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
+ "@utoo/pack": "1.0.0",
11
12
  "compression": "^1.7.4",
12
13
  "connect-history-api-fallback": "^2.0.0",
13
14
  "cors": "^2.8.5",
14
15
  "express": "^4.18.2",
15
16
  "express-http-proxy": "^2.1.1",
16
- "@umijs/bundler-webpack": "4.5.2",
17
- "@umijs/bundler-utils": "4.5.2"
17
+ "@umijs/bundler-utils": "4.6.0",
18
+ "@umijs/bundler-webpack": "4.6.0"
18
19
  },
19
20
  "devDependencies": {
20
- "@utoo/pack": "^0.0.1-alpha.56",
21
21
  "father": "4.1.5"
22
22
  },
23
- "peerDependencies": {
24
- "@utoo/pack": "^0.0.1-alpha.56"
25
- },
26
23
  "publishConfig": {
27
24
  "access": "public"
28
25
  },