@umijs/bundler-utoopack 4.5.3 → 4.6.1

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 +68 -15
  2. package/package.json +4 -7
package/dist/config.js CHANGED
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(config_exports);
26
26
  var import_bundler_webpack = require("@umijs/bundler-webpack");
27
27
  var import_utils = require("@umijs/utils");
28
28
  var import_pack = require("@utoo/pack");
29
+ var import_path = require("path");
29
30
  function convertProcessEnvForUtoopack(webpackConfig) {
30
31
  var _a;
31
32
  let processEnvForUtoopack = {};
@@ -50,7 +51,14 @@ function convertProcessEnvForUtoopack(webpackConfig) {
50
51
  function getModularizeImports(extraBabelPlugins) {
51
52
  return extraBabelPlugins.filter((p) => /^import$|babel-plugin-import/.test(p[0])).reduce(
52
53
  (acc, [_, v]) => {
53
- const { libraryName, libraryDirectory, style, ...rest } = v;
54
+ const {
55
+ libraryName,
56
+ libraryDirectory,
57
+ style,
58
+ camel2DashComponentName,
59
+ transformToDefaultImport,
60
+ ...rest
61
+ } = v;
54
62
  if (Object.keys(rest).length > 0) {
55
63
  throw new Error(
56
64
  `babel-plugin-import options ${Object.keys(
@@ -63,10 +71,15 @@ function getModularizeImports(extraBabelPlugins) {
63
71
  `babel-plugin-import style function is not supported in utoopack bundler`
64
72
  );
65
73
  }
74
+ let transformRule = "{{ kebabCase member }}";
75
+ if (camel2DashComponentName === false) {
76
+ transformRule = "{{ member }}";
77
+ }
78
+ const skipDefaultConversion = typeof transformToDefaultImport === "undefined" ? false : !Boolean(transformToDefaultImport);
66
79
  acc[libraryName] = {
67
- transform: `${libraryName}/${libraryDirectory}/{{ kebabCase member }}`,
80
+ transform: `${libraryName}/${libraryDirectory}/${transformRule}`,
68
81
  preventFullImport: false,
69
- skipDefaultConversion: false,
82
+ skipDefaultConversion,
70
83
  style: typeof style === "boolean" ? "style" : style
71
84
  };
72
85
  return acc;
@@ -76,12 +89,38 @@ function getModularizeImports(extraBabelPlugins) {
76
89
  }
77
90
  function getNormalizedAlias(alias, rootDir) {
78
91
  const newAlias = { ...alias };
79
- if (newAlias.react) {
80
- newAlias["react/*"] = `${newAlias.react}/*`;
92
+ for (const [key, value] of Object.entries(newAlias)) {
93
+ if (key.endsWith("/*") || value.endsWith("/*") || key.endsWith("/") || value.endsWith("/") || key.endsWith("$")) {
94
+ continue;
95
+ }
96
+ if ((0, import_path.extname)(value)) {
97
+ continue;
98
+ }
99
+ newAlias[`${key}/*`] = `${value}/*`;
81
100
  }
82
101
  newAlias[`${rootDir}/*`] = `${rootDir}/*`;
83
102
  return newAlias;
84
103
  }
104
+ function getNormalizedExternals(externals) {
105
+ return Object.entries(externals || {}).reduce(
106
+ (ret, [k, v]) => {
107
+ if (Array.isArray(v)) {
108
+ const [url, ...members] = v;
109
+ ret[k] = {
110
+ // ['antd', 'Button'] => `antd.Button`
111
+ root: members.join("."),
112
+ // `script https://example.com/lib/script.js` => `https://example.com/lib/script.js`
113
+ script: url.replace("script ", "")
114
+ };
115
+ } else if (typeof v === "string") {
116
+ ret[k] = v.replace(/^window(\s+|\.)/, "");
117
+ } else {
118
+ }
119
+ return ret;
120
+ },
121
+ {}
122
+ );
123
+ }
85
124
  async function getProdUtooPackConfig(opts) {
86
125
  var _a;
87
126
  const webpackConfig = await (0, import_bundler_webpack.getConfig)({
@@ -107,7 +146,7 @@ async function getProdUtooPackConfig(opts) {
107
146
  disableCopy: opts.disableCopy
108
147
  });
109
148
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
110
- ...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
149
+ ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
111
150
  compatMode: true
112
151
  });
113
152
  const extraBabelPlugins = [
@@ -116,7 +155,12 @@ async function getProdUtooPackConfig(opts) {
116
155
  ];
117
156
  const modularizeImports = getModularizeImports(extraBabelPlugins);
118
157
  const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
119
- const { publicPath, runtimePublicPath } = opts.config;
158
+ const {
159
+ publicPath,
160
+ runtimePublicPath,
161
+ externals: userExternals,
162
+ copy = []
163
+ } = opts.config;
120
164
  utooBundlerOpts = {
121
165
  ...utooBundlerOpts,
122
166
  config: import_utils.lodash.merge(
@@ -124,13 +168,12 @@ async function getProdUtooPackConfig(opts) {
124
168
  {
125
169
  output: {
126
170
  clean: opts.clean,
127
- publicPath: runtimePublicPath ? "runtime" : publicPath || "/"
171
+ publicPath: runtimePublicPath ? "runtime" : publicPath || "/",
172
+ ...opts.disableCopy ? { copy: [] } : { copy: ["public"].concat(copy) }
128
173
  },
129
174
  optimization: {
130
175
  modularizeImports,
131
176
  concatenateModules: true
132
- // minify: false,
133
- // moduleIds: 'named',
134
177
  },
135
178
  resolve: {
136
179
  alias: getNormalizedAlias(
@@ -149,7 +192,9 @@ async function getProdUtooPackConfig(opts) {
149
192
  // Override process.env for utoopack format
150
193
  define: {
151
194
  "process.env": JSON.stringify(processEnvForUtoopack)
152
- }
195
+ },
196
+ nodePolyfill: true,
197
+ externals: getNormalizedExternals(userExternals)
153
198
  },
154
199
  opts.config.utoopack || {}
155
200
  )
@@ -181,7 +226,7 @@ async function getDevUtooPackConfig(opts) {
181
226
  analyze: process.env.ANALYZE
182
227
  });
183
228
  let utooBundlerOpts = (0, import_pack.compatOptionsFromWebpack)({
184
- ...import_utils.lodash.omit(webpackConfig, ["target", "module"]),
229
+ ...import_utils.lodash.omit(webpackConfig, ["target", "module", "externals"]),
185
230
  compatMode: true
186
231
  });
187
232
  const extraBabelPlugins = [
@@ -190,7 +235,12 @@ async function getDevUtooPackConfig(opts) {
190
235
  ];
191
236
  const modularizeImports = getModularizeImports(extraBabelPlugins);
192
237
  const processEnvForUtoopack = convertProcessEnvForUtoopack(webpackConfig);
193
- const { publicPath, runtimePublicPath } = opts.config;
238
+ const {
239
+ publicPath,
240
+ runtimePublicPath,
241
+ externals: userExternals,
242
+ copy = []
243
+ } = opts.config;
194
244
  utooBundlerOpts = {
195
245
  ...utooBundlerOpts,
196
246
  config: import_utils.lodash.merge(
@@ -199,7 +249,8 @@ async function getDevUtooPackConfig(opts) {
199
249
  output: {
200
250
  // utoopack 的 dev 需要默认清空产物目录
201
251
  clean: opts.clean === void 0 ? true : opts.clean,
202
- publicPath: runtimePublicPath ? "runtime" : publicPath || "/"
252
+ publicPath: runtimePublicPath ? "runtime" : publicPath || "/",
253
+ ...opts.disableCopy ? { copy: [] } : { copy: ["public"].concat(copy) }
203
254
  },
204
255
  resolve: {
205
256
  alias: getNormalizedAlias(
@@ -221,7 +272,9 @@ async function getDevUtooPackConfig(opts) {
221
272
  // Override process.env for utoopack format
222
273
  define: {
223
274
  "process.env": JSON.stringify(processEnvForUtoopack)
224
- }
275
+ },
276
+ nodePolyfill: true,
277
+ externals: getNormalizedExternals(userExternals)
225
278
  },
226
279
  opts.config.utoopack || {}
227
280
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utoopack",
3
- "version": "4.5.3",
3
+ "version": "4.6.1",
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.1",
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-utils": "4.5.3",
17
- "@umijs/bundler-webpack": "4.5.3"
17
+ "@umijs/bundler-webpack": "4.6.1",
18
+ "@umijs/bundler-utils": "4.6.1"
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
  },