@umijs/bundler-webpack 4.0.0-rc.8 → 4.0.0-rc.9

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.
@@ -42,7 +42,8 @@ function addJavaScriptRules(opts) {
42
42
  .test(/\.(js|mjs)$/)
43
43
  .include.add((path) => {
44
44
  try {
45
- if (path.includes('client/client'))
45
+ // do src transform for bundler-webpack/client/client/client.js
46
+ if (path.includes('client/client/client'))
46
47
  return true;
47
48
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
48
49
  }
package/dist/dev.js CHANGED
@@ -22,8 +22,8 @@ const constants_1 = require("./constants");
22
22
  const server_1 = require("./server/server");
23
23
  const types_1 = require("./types");
24
24
  function dev(opts) {
25
- var _a, _b, _c, _d, _e;
26
- var _f;
25
+ var _a, _b, _c, _d, _e, _f;
26
+ var _g;
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
28
  const enableMFSU = opts.config.mfsu !== false;
29
29
  let mfsu = null;
@@ -80,12 +80,13 @@ function dev(opts) {
80
80
  hash: true,
81
81
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
82
82
  name: constants_1.MFSU_NAME,
83
+ chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
83
84
  cache: {
84
- buildDependencies: (_e = opts.cache) === null || _e === void 0 ? void 0 : _e.buildDependencies,
85
+ buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
85
86
  cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
86
87
  },
87
88
  });
88
- (_f = webpackConfig.resolve).alias || (_f.alias = {});
89
+ (_g = webpackConfig.resolve).alias || (_g.alias = {});
89
90
  // TODO: REMOVE ME
90
91
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
91
92
  // @ts-ignore
package/dist/schema.js CHANGED
@@ -40,8 +40,8 @@ function getSchemas() {
40
40
  devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
41
41
  esm: (Joi) => Joi.object(),
42
42
  externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
43
- extraBabelPlugins: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
44
- extraBabelPresets: (Joi) => Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object()))),
43
+ extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
44
+ extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
45
45
  extraPostCSSPlugins: (Joi) => Joi.array(),
46
46
  fastRefresh: (Joi) => Joi.boolean(),
47
47
  forkTSChecker: (Joi) => Joi.object(),
@@ -58,6 +58,7 @@ function getSchemas() {
58
58
  }),
59
59
  mfsu: (Joi) => Joi.alternatives(Joi.object({
60
60
  cacheDirectory: Joi.string(),
61
+ chainWebpack: Joi.function(),
61
62
  esbuild: Joi.boolean(),
62
63
  mfName: Joi.string(),
63
64
  }), Joi.boolean()),
@@ -42,7 +42,7 @@ function createServer(opts) {
42
42
  // cros
43
43
  app.use((_req, res, next) => {
44
44
  res.header('Access-Control-Allow-Origin', '*');
45
- res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
45
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
46
46
  res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
47
47
  next();
48
48
  });
@@ -55,7 +55,7 @@ function createServer(opts) {
55
55
  app.use((req, res, next) => {
56
56
  if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
57
57
  res.setHeader('Content-Type', 'application/javascript');
58
- res.send((0, fs_1.readFileSync)((0, path_1.join)(opts.cwd, 'umi.js'), 'utf-8'));
58
+ (0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
59
59
  }
60
60
  else {
61
61
  next();
@@ -133,7 +133,17 @@ function createServer(opts) {
133
133
  // proxy
134
134
  if (proxy) {
135
135
  Object.keys(proxy).forEach((key) => {
136
- app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(proxy[key]));
136
+ const proxyConfig = proxy[key];
137
+ const target = proxyConfig.target;
138
+ if (target) {
139
+ app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, Object.assign(Object.assign({}, proxy[key]), {
140
+ // Add x-real-url in response header
141
+ onProxyRes(proxyRes, req) {
142
+ var _a;
143
+ proxyRes.headers['x-real-url'] =
144
+ ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
145
+ } })));
146
+ }
137
147
  });
138
148
  }
139
149
  // after middlewares
@@ -155,8 +165,7 @@ function createServer(opts) {
155
165
  res.set('Content-Type', 'text/html');
156
166
  const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
157
167
  if ((0, fs_1.existsSync)(htmlPath)) {
158
- const html = (0, fs_1.readFileSync)(htmlPath, 'utf-8');
159
- res.send(html);
168
+ (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
160
169
  }
161
170
  else {
162
171
  next();
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-rc.8",
3
+ "version": "4.0.0-rc.9",
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,34 +29,34 @@
29
29
  "test": "jest -c ../../jest.turbo.config.ts"
30
30
  },
31
31
  "dependencies": {
32
- "@parcel/css": "1.6.0",
32
+ "@parcel/css": "1.7.2",
33
33
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
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-rc.8",
39
- "@umijs/mfsu": "4.0.0-rc.8",
40
- "@umijs/utils": "4.0.0-rc.8",
38
+ "@umijs/babel-preset-umi": "4.0.0-rc.9",
39
+ "@umijs/mfsu": "4.0.0-rc.9",
40
+ "@umijs/utils": "4.0.0-rc.9",
41
41
  "css-loader": "6.7.1",
42
42
  "es5-imcompatible-versions": "^0.1.73",
43
43
  "jest-worker": "27.5.1",
44
44
  "node-libs-browser": "2.2.1",
45
45
  "postcss": "^8.4.12",
46
- "postcss-preset-env": "7.4.2",
46
+ "postcss-preset-env": "7.4.3",
47
47
  "react-error-overlay": "6.0.9"
48
48
  },
49
49
  "devDependencies": {
50
- "@swc/core": "1.2.156",
50
+ "@swc/core": "1.2.160",
51
51
  "@types/webpack-sources": "3.2.0",
52
52
  "@types/ws": "8.5.3",
53
53
  "autoprefixer": "10.4.4",
54
- "babel-loader": "8.2.3",
54
+ "babel-loader": "8.2.4",
55
55
  "compression": "1.7.4",
56
56
  "connect-history-api-fallback": "1.6.0",
57
57
  "copy-webpack-plugin": "10.2.4",
58
58
  "css-minimizer-webpack-plugin": "3.4.1",
59
- "cssnano": "5.1.4",
59
+ "cssnano": "5.1.5",
60
60
  "fork-ts-checker-webpack-plugin": "7.2.1",
61
61
  "http-proxy-middleware": "2.0.4",
62
62
  "less-loader": "10.2.0",