@umijs/bundler-webpack 4.0.0-beta.13 → 4.0.0-beta.14

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.
@@ -17,6 +17,7 @@ const path_1 = require("path");
17
17
  const webpack_1 = __importDefault(require("../../compiled/webpack"));
18
18
  const webpack_5_chain_1 = __importDefault(require("../../compiled/webpack-5-chain"));
19
19
  const constants_1 = require("../constants");
20
+ const RuntimePublicPathPlugin_1 = require("../plugins/RuntimePublicPathPlugin");
20
21
  const types_1 = require("../types");
21
22
  const browsersList_1 = require("../utils/browsersList");
22
23
  const assetRules_1 = require("./assetRules");
@@ -26,6 +27,7 @@ const copyPlugin_1 = require("./copyPlugin");
26
27
  const cssRules_1 = require("./cssRules");
27
28
  const definePlugin_1 = require("./definePlugin");
28
29
  const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
30
+ const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
29
31
  const ignorePlugin_1 = require("./ignorePlugin");
30
32
  const javaScriptRules_1 = require("./javaScriptRules");
31
33
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
@@ -61,7 +63,6 @@ function getConfig(opts) {
61
63
  // entry
62
64
  Object.keys(opts.entry).forEach((key) => {
63
65
  const entry = config.entry(key);
64
- // TODO: runtimePublicPath
65
66
  if (isDev && opts.hmr) {
66
67
  entry.add(require.resolve('../../client/client/client'));
67
68
  }
@@ -143,6 +144,12 @@ function getConfig(opts) {
143
144
  yield (0, compressPlugin_1.addCompressPlugin)(applyOpts);
144
145
  // purgecss
145
146
  // await applyPurgeCSSWebpackPlugin(applyOpts);
147
+ // handle HarmonyLinkingError
148
+ yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
149
+ // runtimePublicPath
150
+ if (userConfig.runtimePublicPath) {
151
+ config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
152
+ }
146
153
  // analyzer
147
154
  if (opts.analyze) {
148
155
  yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
@@ -0,0 +1,6 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ interface IOpts {
3
+ config: Config;
4
+ }
5
+ export declare function addHarmonyLinkingErrorPlugin(opts: IOpts): Promise<void>;
6
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addHarmonyLinkingErrorPlugin = void 0;
13
+ // ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
14
+ const LINKING_ERROR_TAG = 'was not found in';
15
+ class HarmonyLinkingErrorPlugin {
16
+ apply(compiler) {
17
+ compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
18
+ if (!compilation.warnings.length) {
19
+ return;
20
+ }
21
+ const harmonyLinkingErrors = compilation.warnings.filter((w) => {
22
+ return (w.name === 'ModuleDependencyWarning' &&
23
+ !w.module.resource.includes('node_modules') &&
24
+ w.message.includes(LINKING_ERROR_TAG));
25
+ });
26
+ if (!harmonyLinkingErrors.length) {
27
+ return;
28
+ }
29
+ compilation.errors.push(...harmonyLinkingErrors);
30
+ });
31
+ }
32
+ }
33
+ function addHarmonyLinkingErrorPlugin(opts) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { config } = opts;
36
+ config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
37
+ });
38
+ }
39
+ exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
package/dist/dev.js CHANGED
@@ -20,8 +20,8 @@ const constants_1 = require("./constants");
20
20
  const server_1 = require("./server/server");
21
21
  const types_1 = require("./types");
22
22
  function dev(opts) {
23
- var _a;
24
- var _b;
23
+ var _a, _b, _c;
24
+ var _d;
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  const enableMFSU = opts.config.mfsu !== false;
27
27
  let mfsu = null;
@@ -29,6 +29,11 @@ function dev(opts) {
29
29
  mfsu = new mfsu_1.MFSU({
30
30
  implementor: webpack_1.default,
31
31
  buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
32
+ depBuildConfig: {
33
+ extraPostCSSPlugins: ((_b = opts.config) === null || _b === void 0 ? void 0 : _b.extraPostCSSPlugins) || [],
34
+ },
35
+ mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
36
+ runtimePublicPath: opts.config.runtimePublicPath,
32
37
  });
33
38
  }
34
39
  const webpackConfig = yield (0, config_1.getConfig)({
@@ -59,16 +64,16 @@ function dev(opts) {
59
64
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
60
65
  name: constants_1.MFSU_NAME,
61
66
  });
62
- (_b = webpackConfig.resolve).alias || (_b.alias = {});
67
+ (_d = webpackConfig.resolve).alias || (_d.alias = {});
63
68
  // TODO: REMOVE ME
64
69
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
65
70
  // @ts-ignore
66
71
  webpackConfig.resolve.alias[dep] = require.resolve(dep);
67
72
  });
68
- mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
73
+ yield (mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
69
74
  config: webpackConfig,
70
75
  depConfig: depConfig,
71
- });
76
+ }));
72
77
  yield (0, server_1.createServer)({
73
78
  webpackConfig,
74
79
  userConfig: opts.config,
@@ -0,0 +1,4 @@
1
+ import type { Compiler } from '@umijs/bundler-webpack/compiled/webpack';
2
+ export declare class RuntimePublicPathPlugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RuntimePublicPathPlugin = void 0;
4
+ const PLUGIN_NAME = 'RuntimePublicPath';
5
+ class RuntimePublicPathPlugin {
6
+ apply(compiler) {
7
+ compiler.hooks.make.tap(PLUGIN_NAME, (compilation) => {
8
+ compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module) => {
9
+ // The hook to get the public path ('__webpack_require__.p')
10
+ // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
11
+ if (module.constructor.name === 'PublicPathRuntimeModule') {
12
+ // @ts-ignore
13
+ module._cachedGeneratedCode = `__webpack_require__.p = window.publicPath;`;
14
+ }
15
+ });
16
+ });
17
+ }
18
+ }
19
+ exports.RuntimePublicPathPlugin = RuntimePublicPathPlugin;
package/dist/schema.js CHANGED
@@ -52,12 +52,14 @@ function getSchemas() {
52
52
  lessLoader: (Joi) => Joi.object(),
53
53
  mfsu: (Joi) => Joi.alternatives(Joi.object({
54
54
  esbuild: Joi.boolean(),
55
+ mfName: Joi.string(),
55
56
  }), Joi.boolean()),
56
57
  outputPath: (Joi) => Joi.string(),
57
58
  postcssLoader: (Joi) => Joi.object(),
58
59
  proxy: (Joi) => Joi.object(),
59
60
  publicPath: (Joi) => Joi.string(),
60
61
  purgeCSS: (Joi) => Joi.object(),
62
+ runtimePublicPath: (Joi) => Joi.object(),
61
63
  sassLoader: (Joi) => Joi.object(),
62
64
  srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
63
65
  styleLoader: (Joi) => Joi.object(),
@@ -27,6 +27,23 @@ function createServer(opts) {
27
27
  const { webpackConfig, userConfig } = opts;
28
28
  const { proxy } = userConfig;
29
29
  const app = (0, express_1.default)();
30
+ // basename middleware
31
+ app.use((req, _res, next) => {
32
+ const { url, path } = req;
33
+ const { basename } = userConfig;
34
+ if (basename !== '/' && url.startsWith(basename)) {
35
+ req.url = url.slice(basename.length);
36
+ req.path = path.slice(basename.length);
37
+ }
38
+ next();
39
+ });
40
+ // cros
41
+ app.use((_req, res, next) => {
42
+ res.header('Access-Control-Allow-Origin', '*');
43
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
44
+ res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
45
+ next();
46
+ });
30
47
  // compression
31
48
  app.use(require('@umijs/bundler-webpack/compiled/compression')());
32
49
  // TODO: headers
package/dist/types.d.ts CHANGED
@@ -34,6 +34,7 @@ declare type IBabelPlugin = Function | string | [string, {
34
34
  export interface IConfig {
35
35
  alias?: Record<string, string>;
36
36
  autoCSSModules?: boolean;
37
+ base?: string;
37
38
  chainWebpack?: Function;
38
39
  copy?: ICopy[] | string[];
39
40
  cssLoader?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-beta.13",
3
+ "version": "4.0.0-beta.14",
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",
@@ -34,9 +34,9 @@
34
34
  "@svgr/plugin-svgo": "^6.1.0",
35
35
  "@swc/core": "1.2.117",
36
36
  "@types/hapi__joi": "17.1.7",
37
- "@umijs/babel-preset-umi": "4.0.0-beta.13",
38
- "@umijs/mfsu": "4.0.0-beta.13",
39
- "@umijs/utils": "4.0.0-beta.13",
37
+ "@umijs/babel-preset-umi": "4.0.0-beta.14",
38
+ "@umijs/mfsu": "4.0.0-beta.14",
39
+ "@umijs/utils": "4.0.0-beta.14",
40
40
  "css-loader": "6.5.1",
41
41
  "es5-imcompatible-versions": "^0.1.73",
42
42
  "jest-worker": "27.4.2",