@umijs/bundler-webpack 4.0.55 → 4.0.57

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.
@@ -62,14 +62,14 @@ async function addCSSRules(opts) {
62
62
  const nestRulesConfig = [
63
63
  userConfig.autoCSSModules && {
64
64
  rule: rule.test(test).oneOf("css-modules").resourceQuery(/modules/),
65
- isCSSModules: true
65
+ isAutoCSSModuleRule: true
66
66
  },
67
67
  {
68
68
  rule: rule.test(test).oneOf("css").sideEffects(true),
69
- isCSSModules: false
69
+ isAutoCSSModuleRule: false
70
70
  }
71
71
  ].filter(Boolean);
72
- for (const { rule: rule2, isCSSModules } of nestRulesConfig) {
72
+ for (const { rule: rule2, isAutoCSSModuleRule } of nestRulesConfig) {
73
73
  if (userConfig.styleLoader) {
74
74
  rule2.use("style-loader").loader(
75
75
  require.resolve("@umijs/bundler-webpack/compiled/style-loader")
@@ -83,6 +83,23 @@ async function addCSSRules(opts) {
83
83
  esModule: true
84
84
  });
85
85
  }
86
+ const getLocalIdent = userConfig.ssr && getLocalIdentForSSR;
87
+ const localIdentName = "[local]___[hash:base64:5]";
88
+ let cssLoaderModulesConfig;
89
+ if (isAutoCSSModuleRule) {
90
+ cssLoaderModulesConfig = {
91
+ localIdentName,
92
+ ...userConfig.cssLoaderModules,
93
+ getLocalIdent
94
+ };
95
+ } else if (userConfig.normalCSSLoaderModules) {
96
+ cssLoaderModulesConfig = {
97
+ localIdentName,
98
+ auto: true,
99
+ ...userConfig.normalCSSLoaderModules,
100
+ getLocalIdent
101
+ };
102
+ }
86
103
  rule2.use("css-loader").loader(require.resolve("css-loader")).options({
87
104
  importLoaders: 1,
88
105
  esModule: true,
@@ -94,25 +111,7 @@ async function addCSSRules(opts) {
94
111
  }
95
112
  },
96
113
  import: true,
97
- ...isCSSModules ? {
98
- modules: {
99
- localIdentName: "[local]___[hash:base64:5]",
100
- ...userConfig.cssLoaderModules,
101
- // If SSR is enabled, we need to handling the css modules name hashing
102
- // and save the class names mapping into opts.cssModulesMapping
103
- // so the esbuild can use it to generate the correct name for the server side
104
- getLocalIdent: userConfig.ssr && ((context, localIdentName, localName, opt) => {
105
- const classIdent = ((0, import_utils.winPath)(context.resourcePath).replace(
106
- (0, import_utils.winPath)(ensureLastSlash(opt.context)),
107
- ""
108
- ) + "@" + localName).trim();
109
- let hash = Buffer.from(classIdent).toString("base64").replace(/=/g, "");
110
- hash = hash.substring(hash.length - 5);
111
- const result = localIdentName.replace(/\[local]/g, localName).replace(/\[hash[^\[]*?]/g, hash);
112
- return result;
113
- })
114
- }
115
- } : {},
114
+ modules: cssLoaderModulesConfig,
116
115
  ...userConfig.cssLoader
117
116
  });
118
117
  rule2.use("postcss-loader").loader(
@@ -143,6 +142,16 @@ async function addCSSRules(opts) {
143
142
  function ensureLastSlash(path) {
144
143
  return path.endsWith("/") ? path : path + "/";
145
144
  }
145
+ function getLocalIdentForSSR(context, localIdentName, localName, opt) {
146
+ const classIdent = ((0, import_utils.winPath)(context.resourcePath).replace(
147
+ (0, import_utils.winPath)(ensureLastSlash(opt.context)),
148
+ ""
149
+ ) + "@" + localName).trim();
150
+ let hash = Buffer.from(classIdent).toString("base64").replace(/=/g, "");
151
+ hash = hash.substring(hash.length - 5);
152
+ const result = localIdentName.replace(/\[local]/g, localName).replace(/\[hash[^\[]*?]/g, hash);
153
+ return result;
154
+ }
146
155
  // Annotate the CommonJS export names for ESM import in node:
147
156
  0 && (module.exports = {
148
157
  addCSSRules
@@ -3,5 +3,6 @@ export declare class EsbuildMinifyFix {
3
3
  private name;
4
4
  constructor();
5
5
  apply(compiler: Compiler): void;
6
+ private isIIFE;
6
7
  minifyFix(compilation: Compilation, assets: Record<string, sources.Source>): Promise<void>;
7
8
  }
@@ -41,6 +41,16 @@ var EsbuildMinifyFix = class {
41
41
  );
42
42
  });
43
43
  }
44
+ isIIFE(source) {
45
+ source = source.trim();
46
+ if (source.startsWith('(function(){"use strict";')) {
47
+ return true;
48
+ }
49
+ if (source.startsWith("(function(){") && (source.endsWith("})()") || source.endsWith("})();"))) {
50
+ return true;
51
+ }
52
+ return false;
53
+ }
44
54
  async minifyFix(compilation, assets) {
45
55
  const matchObject = import_webpack.ModuleFilenameHelpers.matchObject.bind(void 0, {
46
56
  include: [JS_FILE_REG]
@@ -57,6 +67,9 @@ var EsbuildMinifyFix = class {
57
67
  if (info == null ? void 0 : info.EsbuildMinifyFix) {
58
68
  return false;
59
69
  }
70
+ if (name.endsWith(".worker.js")) {
71
+ return false;
72
+ }
60
73
  return true;
61
74
  }).map(async (name) => {
62
75
  const { info, source } = compilation.getAsset(name);
@@ -72,9 +85,9 @@ var EsbuildMinifyFix = class {
72
85
  const { source, map } = inputSource.sourceAndMap();
73
86
  const originCode = source.toString();
74
87
  let newCode = originCode;
75
- if (!newCode.startsWith('"use strict";(self.') && !newCode.startsWith('(function(){"use strict";') && !newCode.startsWith("(self.webpack")) {
88
+ if (!newCode.startsWith('"use strict";(self.') && !newCode.startsWith("(self.webpack") && !this.isIIFE(newCode)) {
76
89
  const bundle = new import_utils.MagicString(newCode);
77
- bundle.indent().prepend("!(function () {\n").append("}());");
90
+ bundle.prepend("!(function(){").append("}());");
78
91
  newCode = bundle.toString();
79
92
  const output = {};
80
93
  if (map) {
package/dist/schema.js CHANGED
@@ -135,6 +135,7 @@ function getSchemas() {
135
135
  }),
136
136
  Joi.boolean()
137
137
  ),
138
+ normalCSSLoaderModules: (Joi) => Joi.object(),
138
139
  outputPath: (Joi) => Joi.string(),
139
140
  postcssLoader: (Joi) => Joi.object(),
140
141
  proxy: (Joi) => Joi.alternatives().try(Joi.object(), Joi.array()),
@@ -8,6 +8,6 @@ import { Server as HttpsServer } from 'https';
8
8
  import WebSocket from '../../compiled/ws';
9
9
  export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
10
10
  send(message: string): void;
11
- wss: WebSocket.Server<WebSocket.WebSocket>;
11
+ wss: WebSocket.Server;
12
12
  close(): void;
13
13
  };
package/dist/types.d.ts CHANGED
@@ -90,6 +90,9 @@ export interface IConfig {
90
90
  lessLoader?: {
91
91
  [key: string]: any;
92
92
  };
93
+ normalCSSLoaderModules?: {
94
+ [key: string]: any;
95
+ };
93
96
  outputPath?: string;
94
97
  postcssLoader?: {
95
98
  [key: string]: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.55",
3
+ "version": "4.0.57",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -33,11 +33,11 @@
33
33
  "@svgr/plugin-jsx": "^6.5.1",
34
34
  "@svgr/plugin-svgo": "^6.5.1",
35
35
  "@types/hapi__joi": "17.1.9",
36
- "@umijs/babel-preset-umi": "4.0.55",
37
- "@umijs/bundler-utils": "4.0.55",
36
+ "@umijs/babel-preset-umi": "4.0.57",
37
+ "@umijs/bundler-utils": "4.0.57",
38
38
  "@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
39
- "@umijs/mfsu": "4.0.55",
40
- "@umijs/utils": "4.0.55",
39
+ "@umijs/mfsu": "4.0.57",
40
+ "@umijs/utils": "4.0.57",
41
41
  "cors": "^2.8.5",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.78",