@umijs/bundler-webpack 4.0.0-beta.5 → 4.0.0-beta.6

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.
package/dist/build.d.ts CHANGED
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  onBuildComplete?: Function;
7
7
  babelPreset?: any;
8
8
  chainWebpack?: Function;
9
+ modifyWebpackConfig?: Function;
9
10
  beforeBabelPlugins?: any[];
10
11
  beforeBabelPresets?: any[];
11
12
  extraBabelPlugins?: any[];
package/dist/build.js CHANGED
@@ -35,6 +35,7 @@ function build(opts) {
35
35
  ...(opts.extraBabelPresets || []),
36
36
  ],
37
37
  chainWebpack: opts.chainWebpack,
38
+ modifyWebpackConfig: opts.modifyWebpackConfig,
38
39
  });
39
40
  let isFirstCompile = true;
40
41
  return new Promise((resolve, reject) => {
package/dist/cli.js CHANGED
@@ -1,23 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -36,7 +17,6 @@ const utils_1 = require("@umijs/utils");
36
17
  const assert_1 = __importDefault(require("assert"));
37
18
  const fs_1 = require("fs");
38
19
  const path_1 = require("path");
39
- const process = __importStar(require("process"));
40
20
  const build_1 = require("./build");
41
21
  const dev_1 = require("./dev");
42
22
  const args = (0, utils_1.yParser)(process.argv.slice(2), {});
@@ -8,6 +8,7 @@ interface IOpts {
8
8
  extraBabelPlugins?: any[];
9
9
  babelPreset?: any;
10
10
  chainWebpack?: Function;
11
+ modifyWebpackConfig?: Function;
11
12
  hash?: boolean;
12
13
  hmr?: boolean;
13
14
  staticPathPrefix?: string;
@@ -111,6 +111,7 @@ function getConfig(opts) {
111
111
  // experiments
112
112
  config.experiments({
113
113
  topLevelAwait: true,
114
+ outputModule: !!userConfig.esm,
114
115
  });
115
116
  // node polyfill
116
117
  yield (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
@@ -165,6 +166,12 @@ function getConfig(opts) {
165
166
  webpackConfig = yield (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
166
167
  webpackConfig,
167
168
  });
169
+ if (opts.modifyWebpackConfig) {
170
+ webpackConfig = yield opts.modifyWebpackConfig(webpackConfig, {
171
+ env: opts.env,
172
+ webpack: webpack_1.default,
173
+ });
174
+ }
168
175
  return webpackConfig;
169
176
  });
170
177
  }
@@ -8,10 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.addJavaScriptRules = void 0;
13
16
  const utils_1 = require("@umijs/utils");
14
17
  const constants_1 = require("../constants");
18
+ const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
15
19
  const types_1 = require("../types");
16
20
  const depMatch_1 = require("../utils/depMatch");
17
21
  function addJavaScriptRules(opts) {
@@ -130,6 +134,7 @@ function addJavaScriptRules(opts) {
130
134
  },
131
135
  },
132
136
  },
137
+ plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
133
138
  });
134
139
  }
135
140
  else {
package/dist/dev.d.ts CHANGED
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  port?: number;
7
7
  host?: string;
8
8
  chainWebpack?: Function;
9
+ modifyWebpackConfig?: Function;
9
10
  beforeBabelPlugins?: any[];
10
11
  beforeBabelPresets?: any[];
11
12
  extraBabelPlugins?: any[];
package/dist/dev.js CHANGED
@@ -21,9 +21,11 @@ const server_1 = require("./server/server");
21
21
  const types_1 = require("./types");
22
22
  function dev(opts) {
23
23
  var _a;
24
+ var _b;
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  const mfsu = new mfsu_1.MFSU({
26
27
  implementor: webpack_1.default,
28
+ buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
27
29
  });
28
30
  const webpackConfig = yield (0, config_1.getConfig)({
29
31
  cwd: opts.cwd,
@@ -40,6 +42,7 @@ function dev(opts) {
40
42
  ...(opts.extraBabelPresets || []),
41
43
  ],
42
44
  chainWebpack: opts.chainWebpack,
45
+ modifyWebpackConfig: opts.modifyWebpackConfig,
43
46
  hmr: true,
44
47
  analyze: process.env.ANALYZE,
45
48
  });
@@ -52,7 +55,7 @@ function dev(opts) {
52
55
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
53
56
  name: constants_1.MFSU_NAME,
54
57
  });
55
- (_a = webpackConfig.resolve).alias || (_a.alias = {});
58
+ (_b = webpackConfig.resolve).alias || (_b.alias = {});
56
59
  // TODO: REMOVE ME
57
60
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
58
61
  // @ts-ignore
package/dist/schema.js CHANGED
@@ -50,7 +50,9 @@ function getSchemas() {
50
50
  jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
51
51
  jsMinifierOptions: (Joi) => Joi.object(),
52
52
  lessLoader: (Joi) => Joi.object(),
53
- mfsu: (Joi) => Joi.alternatives(Joi.object(), Joi.boolean()),
53
+ mfsu: (Joi) => Joi.alternatives(Joi.object({
54
+ esbuild: Joi.boolean(),
55
+ }), Joi.boolean()),
54
56
  outputPath: (Joi) => Joi.string(),
55
57
  postcssLoader: (Joi) => Joi.object(),
56
58
  proxy: (Joi) => Joi.object(),
@@ -63,6 +65,8 @@ function getSchemas() {
63
65
  svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
64
66
  targets: (Joi) => Joi.object(),
65
67
  writeToDisk: (Joi) => Joi.boolean(),
68
+ esm: (Joi) => Joi.object(),
69
+ theme: (Joi) => Joi.object(),
66
70
  };
67
71
  }
68
72
  exports.getSchemas = getSchemas;
@@ -32,6 +32,16 @@ function createServer(opts) {
32
32
  // TODO: headers
33
33
  // before middlewares
34
34
  (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
35
+ // TODO: add to before middleware
36
+ app.use((req, res, next) => {
37
+ if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
38
+ res.setHeader('Content-Type', 'application/javascript');
39
+ res.send((0, fs_1.readFileSync)((0, path_1.join)(opts.cwd, 'umi.js'), 'utf-8'));
40
+ }
41
+ else {
42
+ next();
43
+ }
44
+ });
35
45
  // webpack dev middleware
36
46
  const compiler = (0, webpack_1.default)(Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig]);
37
47
  const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
@@ -117,15 +127,6 @@ function createServer(opts) {
117
127
  app.use('/__umi_ping', (_, res) => {
118
128
  res.end('pong');
119
129
  });
120
- // TODO: remove me
121
- app.use((req, res, next) => {
122
- if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
123
- res.send((0, fs_1.readFileSync)((0, path_1.join)(opts.cwd, 'umi.js'), 'utf-8'));
124
- }
125
- else {
126
- next();
127
- }
128
- });
129
130
  // index.html
130
131
  // TODO: remove me
131
132
  app.get('/', (_req, res, next) => {
@@ -0,0 +1,8 @@
1
+ import { ImportDeclaration, TsType, VariableDeclaration } from '@swc/core';
2
+ import Visitor from '@swc/core/Visitor';
3
+ declare class AutoCSSModule extends Visitor {
4
+ visitTsType(expression: TsType): TsType;
5
+ visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
6
+ visitVariableDeclaration(expression: VariableDeclaration): VariableDeclaration;
7
+ }
8
+ export default AutoCSSModule;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
7
+ const path_1 = require("path");
8
+ const CSS_EXT_NAMES = ['.css', '.less', '.sass', '.scss', '.stylus', '.styl'];
9
+ class AutoCSSModule extends Visitor_1.default {
10
+ visitTsType(expression) {
11
+ return expression;
12
+ }
13
+ visitImportDeclaration(expression) {
14
+ const { specifiers, source } = expression;
15
+ const { value } = source;
16
+ if (specifiers.length && CSS_EXT_NAMES.includes((0, path_1.extname)(value))) {
17
+ return Object.assign(Object.assign({}, expression), { source: Object.assign(Object.assign({}, source), { value: `${value}?modules` }) });
18
+ }
19
+ return expression;
20
+ }
21
+ visitVariableDeclaration(expression) {
22
+ const { declarations } = expression;
23
+ if (declarations.length &&
24
+ declarations[0].init &&
25
+ declarations[0].init.type === 'AwaitExpression' &&
26
+ declarations[0].init.argument.type === 'CallExpression' &&
27
+ declarations[0].init.argument.arguments[0].expression.type ===
28
+ 'StringLiteral' &&
29
+ CSS_EXT_NAMES.includes((0, path_1.extname)(declarations[0].init.argument.arguments[0].expression.value))) {
30
+ declarations[0].init.argument.arguments[0].expression.value = `${declarations[0].init.argument.arguments[0].expression.value}?modules`;
31
+ }
32
+ return expression;
33
+ }
34
+ }
35
+ exports.default = AutoCSSModule;
package/dist/types.d.ts CHANGED
@@ -52,6 +52,9 @@ export interface IConfig {
52
52
  depTranspiler?: Transpiler;
53
53
  devtool?: Config.DevTool;
54
54
  externals?: WebpackConfig['externals'];
55
+ esm?: {
56
+ [key: string]: any;
57
+ };
55
58
  extraBabelPlugins?: IBabelPlugin[];
56
59
  extraBabelPresets?: IBabelPlugin[];
57
60
  extraPostCSSPlugins?: any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-beta.5",
3
+ "version": "4.0.0-beta.6",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,9 +37,9 @@
37
37
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.1",
38
38
  "@swc/core": "1.2.105",
39
39
  "@types/hapi__joi": "17.1.7",
40
- "@umijs/babel-preset-umi": "4.0.0-beta.5",
41
- "@umijs/mfsu": "4.0.0-beta.5",
42
- "@umijs/utils": "4.0.0-beta.5",
40
+ "@umijs/babel-preset-umi": "4.0.0-beta.6",
41
+ "@umijs/mfsu": "4.0.0-beta.6",
42
+ "@umijs/utils": "4.0.0-beta.6",
43
43
  "css-loader": "6.5.0",
44
44
  "es5-imcompatible-versions": "^0.1.73",
45
45
  "jest-worker": "27.3.1",