@umijs/bundler-webpack 4.0.0-rc.19 → 4.0.0-rc.21

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.
@@ -166,13 +166,14 @@ async function getConfig(opts) {
166
166
  // tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
167
167
  // 使用 immutablePaths 避免 node_modules 的内容被写入缓存
168
168
  // tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
169
+ // 同时配置 managedPaths 将 tnpm 的软连接结构标记为可信,避免执行快照序列化时 OOM
169
170
  // ref: smallfish
170
171
  if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
172
+ const nodeModulesPath = opts.cache.absNodeModulesPath ||
173
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules');
171
174
  config.snapshot({
172
- immutablePaths: [
173
- opts.cache.absNodeModulesPath ||
174
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules'),
175
- ],
175
+ immutablePaths: [nodeModulesPath],
176
+ managedPaths: [nodeModulesPath],
176
177
  });
177
178
  }
178
179
  config.infrastructureLogging({
@@ -10,6 +10,9 @@ class RuntimePublicPathPlugin {
10
10
  // The hook to get the public path ('__webpack_require__.p')
11
11
  // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
12
  if (module.constructor.name === 'PublicPathRuntimeModule') {
13
+ // If current public path is handled by mini-css-extract-plugin, skip it
14
+ if (module.getGeneratedCode().includes('webpack:///mini-css-extract-plugin'))
15
+ return;
13
16
  // @ts-ignore
14
17
  module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
15
18
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
3
4
  import http from 'http';
4
5
  import { IConfig } from '../types';
@@ -9,6 +9,7 @@ const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express
9
9
  const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
10
10
  const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
11
11
  const utils_1 = require("@umijs/utils");
12
+ const cors_1 = __importDefault(require("cors"));
12
13
  const fs_1 = require("fs");
13
14
  const http_1 = __importDefault(require("http"));
14
15
  const path_1 = require("path");
@@ -19,12 +20,11 @@ async function createServer(opts) {
19
20
  const { proxy } = userConfig;
20
21
  const app = (0, express_1.default)();
21
22
  // cros
22
- app.use((_req, res, next) => {
23
- res.header('Access-Control-Allow-Origin', '*');
24
- res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
25
- res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
26
- next();
27
- });
23
+ app.use((0, cors_1.default)({
24
+ origin: true,
25
+ methods: ['GET', 'HEAD', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS'],
26
+ credentials: true,
27
+ }));
28
28
  // compression
29
29
  app.use(require('@umijs/bundler-webpack/compiled/compression')());
30
30
  // TODO: headers
@@ -32,9 +32,11 @@ async function createServer(opts) {
32
32
  (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
33
33
  // TODO: add to before middleware
34
34
  app.use((req, res, next) => {
35
- if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
36
- res.setHeader('Content-Type', 'application/javascript');
37
- (0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
35
+ const file = req.path;
36
+ const filePath = (0, path_1.join)(opts.cwd, file);
37
+ const ext = (0, path_1.extname)(filePath);
38
+ if (ext === '.js' && (0, fs_1.existsSync)(filePath)) {
39
+ res.sendFile(filePath);
38
40
  }
39
41
  else {
40
42
  next();
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import type { SpdyServer as Server } from '@umijs/bundler-utils';
3
5
  import { Server as HttpServer } from 'http';
4
6
  import { Http2Server } from 'http2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-rc.19",
3
+ "version": "4.0.0-rc.21",
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,16 +29,17 @@
29
29
  "test": "umi-scripts jest-turbo"
30
30
  },
31
31
  "dependencies": {
32
- "@parcel/css": "1.8.2",
33
- "@pmmmwh/react-refresh-webpack-plugin": "0.5.5",
32
+ "@parcel/css": "1.9.0",
33
+ "@pmmmwh/react-refresh-webpack-plugin": "0.5.7",
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.19",
39
- "@umijs/bundler-utils": "4.0.0-rc.19",
40
- "@umijs/mfsu": "4.0.0-rc.19",
41
- "@umijs/utils": "4.0.0-rc.19",
38
+ "@umijs/babel-preset-umi": "4.0.0-rc.21",
39
+ "@umijs/bundler-utils": "4.0.0-rc.21",
40
+ "@umijs/mfsu": "4.0.0-rc.21",
41
+ "@umijs/utils": "4.0.0-rc.21",
42
+ "cors": "^2.8.5",
42
43
  "css-loader": "6.7.1",
43
44
  "es5-imcompatible-versions": "^0.1.73",
44
45
  "jest-worker": "27.5.1",
@@ -49,6 +50,7 @@
49
50
  },
50
51
  "devDependencies": {
51
52
  "@swc/core": "1.2.165",
53
+ "@types/cors": "^2.8.12",
52
54
  "@types/webpack-sources": "3.2.0",
53
55
  "@types/ws": "8.5.3",
54
56
  "autoprefixer": "10.4.4",
@@ -74,10 +76,10 @@
74
76
  "terser": "5.12.1",
75
77
  "terser-webpack-plugin": "5.3.1",
76
78
  "url-loader": "4.1.1",
77
- "webpack": "5.72.0",
79
+ "webpack": "5.72.1",
78
80
  "webpack-5-chain": "8.0.0",
79
81
  "webpack-bundle-analyzer": "4.5.0",
80
- "webpack-dev-middleware": "5.3.1",
82
+ "webpack-dev-middleware": "5.3.3",
81
83
  "webpack-manifest-plugin": "5.0.0",
82
84
  "webpack-sources": "3.2.3",
83
85
  "ws": "8.5.0"