@umijs/bundler-webpack 4.0.0-beta.1 → 4.0.0-beta.10
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/compiled/@svgr/webpack/index.js +77 -154
- package/compiled/@svgr/webpack/package.json +1 -1
- package/compiled/webpack/index.js +2731 -2597
- package/compiled/webpack/lazy-compilation-node.js +3 -1
- package/compiled/webpack/package.json +5 -1
- package/compiled/webpack/types.d.ts +40 -9
- package/dist/build.d.ts +7 -0
- package/dist/build.js +11 -0
- package/dist/cli.js +0 -20
- package/dist/config/assetRules.js +14 -1
- package/dist/config/config.d.ts +4 -0
- package/dist/config/config.js +16 -1
- package/dist/config/cssRules.js +3 -3
- package/dist/config/javaScriptRules.d.ts +2 -0
- package/dist/config/javaScriptRules.js +8 -3
- package/dist/config/svgRules.js +3 -16
- package/dist/dev.d.ts +6 -0
- package/dist/dev.js +23 -7
- package/dist/schema.js +5 -1
- package/dist/server/server.js +10 -9
- package/dist/server/ws.d.ts +1 -1
- package/dist/server/ws.js +1 -1
- package/dist/swcPlugins/autoCSSModules.d.ts +8 -0
- package/dist/swcPlugins/autoCSSModules.js +35 -0
- package/dist/types.d.ts +3 -0
- package/package.json +23 -23
- package/compiled/@svgr/webpack/.svgo.yml +0 -75
|
@@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
|
|
|
9
9
|
var active = options.active;
|
|
10
10
|
var module = options.module;
|
|
11
11
|
var response;
|
|
12
|
-
var request =
|
|
12
|
+
var request = (
|
|
13
|
+
urlBase.startsWith("https") ? require("https") : require("http")
|
|
14
|
+
).request(
|
|
13
15
|
urlBase + data,
|
|
14
16
|
{
|
|
15
17
|
agent: false,
|
|
@@ -80,6 +80,8 @@ import {
|
|
|
80
80
|
WithStatement,
|
|
81
81
|
YieldExpression
|
|
82
82
|
} from "estree";
|
|
83
|
+
import { ServerOptions as ServerOptionsImport } from 'http';
|
|
84
|
+
import { ListenOptions, Server } from 'net';
|
|
83
85
|
import { validate as validateFunction } from './schema-utils';
|
|
84
86
|
import { default as ValidationError } from './schema-utils/declarations/ValidationError';
|
|
85
87
|
import { ValidationErrorConfiguration } from './schema-utils/declarations/validate';
|
|
@@ -95,6 +97,7 @@ import {
|
|
|
95
97
|
SyncHook,
|
|
96
98
|
SyncWaterfallHook
|
|
97
99
|
} from "tapable";
|
|
100
|
+
import { SecureContextOptions, TlsOptions } from 'tls';
|
|
98
101
|
|
|
99
102
|
declare class AbstractLibraryPlugin<T> {
|
|
100
103
|
constructor(__0: {
|
|
@@ -383,6 +386,10 @@ declare class AutomaticPrefetchPlugin {
|
|
|
383
386
|
apply(compiler: Compiler): void;
|
|
384
387
|
}
|
|
385
388
|
type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
|
|
389
|
+
declare interface BackendApi {
|
|
390
|
+
dispose: (arg0?: Error) => void;
|
|
391
|
+
module: (arg0: Module) => { client: string; data: string; active: boolean };
|
|
392
|
+
}
|
|
386
393
|
declare class BannerPlugin {
|
|
387
394
|
constructor(options: BannerPluginArgument);
|
|
388
395
|
options: BannerPluginOptions;
|
|
@@ -5794,25 +5801,45 @@ declare interface KnownStatsProfile {
|
|
|
5794
5801
|
dependencies: number;
|
|
5795
5802
|
}
|
|
5796
5803
|
|
|
5804
|
+
/**
|
|
5805
|
+
* Options for the default backend.
|
|
5806
|
+
*/
|
|
5807
|
+
declare interface LazyCompilationDefaultBackendOptions {
|
|
5808
|
+
/**
|
|
5809
|
+
* A custom client.
|
|
5810
|
+
*/
|
|
5811
|
+
client?: string;
|
|
5812
|
+
|
|
5813
|
+
/**
|
|
5814
|
+
* Specifies where to listen to from the server.
|
|
5815
|
+
*/
|
|
5816
|
+
listen?: number | ListenOptions | ((server: typeof Server) => void);
|
|
5817
|
+
|
|
5818
|
+
/**
|
|
5819
|
+
* Specifies the protocol the client should use to connect to the server.
|
|
5820
|
+
*/
|
|
5821
|
+
protocol?: "http" | "https";
|
|
5822
|
+
|
|
5823
|
+
/**
|
|
5824
|
+
* Specifies how to create the server handling the EventSource requests.
|
|
5825
|
+
*/
|
|
5826
|
+
server?: ServerOptionsImport | ServerOptionsHttps | (() => typeof Server);
|
|
5827
|
+
}
|
|
5828
|
+
|
|
5797
5829
|
/**
|
|
5798
5830
|
* Options for compiling entrypoints and import()s only when they are accessed.
|
|
5799
5831
|
*/
|
|
5800
5832
|
declare interface LazyCompilationOptions {
|
|
5801
5833
|
/**
|
|
5802
|
-
*
|
|
5834
|
+
* Specifies the backend that should be used for handling client keep alive.
|
|
5803
5835
|
*/
|
|
5804
5836
|
backend?:
|
|
5805
5837
|
| ((
|
|
5806
5838
|
compiler: Compiler,
|
|
5807
|
-
|
|
5808
|
-
callback: (err?: Error, api?: any) => void
|
|
5839
|
+
callback: (err?: Error, api?: BackendApi) => void
|
|
5809
5840
|
) => void)
|
|
5810
|
-
| ((compiler: Compiler
|
|
5811
|
-
|
|
5812
|
-
/**
|
|
5813
|
-
* A custom client.
|
|
5814
|
-
*/
|
|
5815
|
-
client?: string;
|
|
5841
|
+
| ((compiler: Compiler) => Promise<BackendApi>)
|
|
5842
|
+
| LazyCompilationDefaultBackendOptions;
|
|
5816
5843
|
|
|
5817
5844
|
/**
|
|
5818
5845
|
* Enable/disable lazy compilation for entries.
|
|
@@ -7485,6 +7512,7 @@ declare interface NormalModuleLoaderContext<OptionsType> {
|
|
|
7485
7512
|
utils: {
|
|
7486
7513
|
absolutify: (context: string, request: string) => string;
|
|
7487
7514
|
contextify: (context: string, request: string) => string;
|
|
7515
|
+
createHash: (algorithm?: string) => Hash;
|
|
7488
7516
|
};
|
|
7489
7517
|
rootContext: string;
|
|
7490
7518
|
fs: InputFileSystem;
|
|
@@ -10369,6 +10397,9 @@ declare abstract class Serializer {
|
|
|
10369
10397
|
serialize(obj?: any, context?: any): any;
|
|
10370
10398
|
deserialize(value?: any, context?: any): any;
|
|
10371
10399
|
}
|
|
10400
|
+
type ServerOptionsHttps = SecureContextOptions &
|
|
10401
|
+
TlsOptions &
|
|
10402
|
+
ServerOptionsImport;
|
|
10372
10403
|
declare class SharePlugin {
|
|
10373
10404
|
constructor(options: SharePluginOptions);
|
|
10374
10405
|
|
package/dist/build.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ interface IOpts {
|
|
|
4
4
|
entry: Record<string, string>;
|
|
5
5
|
config: IConfig;
|
|
6
6
|
onBuildComplete?: Function;
|
|
7
|
+
babelPreset?: any;
|
|
8
|
+
chainWebpack?: Function;
|
|
9
|
+
modifyWebpackConfig?: Function;
|
|
10
|
+
beforeBabelPlugins?: any[];
|
|
11
|
+
beforeBabelPresets?: any[];
|
|
12
|
+
extraBabelPlugins?: any[];
|
|
13
|
+
extraBabelPresets?: any[];
|
|
7
14
|
clean?: boolean;
|
|
8
15
|
}
|
|
9
16
|
export declare function build(opts: IOpts): Promise<void>;
|
package/dist/build.js
CHANGED
|
@@ -25,6 +25,17 @@ function build(opts) {
|
|
|
25
25
|
entry: opts.entry,
|
|
26
26
|
userConfig: opts.config,
|
|
27
27
|
analyze: process.env.ANALYZE,
|
|
28
|
+
babelPreset: opts.babelPreset,
|
|
29
|
+
extraBabelPlugins: [
|
|
30
|
+
...(opts.beforeBabelPlugins || []),
|
|
31
|
+
...(opts.extraBabelPlugins || []),
|
|
32
|
+
],
|
|
33
|
+
extraBabelPresets: [
|
|
34
|
+
...(opts.beforeBabelPresets || []),
|
|
35
|
+
...(opts.extraBabelPresets || []),
|
|
36
|
+
],
|
|
37
|
+
chainWebpack: opts.chainWebpack,
|
|
38
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
28
39
|
});
|
|
29
40
|
let isFirstCompile = true;
|
|
30
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), {});
|
|
@@ -40,9 +40,22 @@ function addAssetRules(opts) {
|
|
|
40
40
|
.generator({
|
|
41
41
|
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
42
42
|
});
|
|
43
|
+
rule
|
|
44
|
+
.oneOf('svg')
|
|
45
|
+
.type('asset')
|
|
46
|
+
.resourceQuery(/url/)
|
|
47
|
+
.parser({
|
|
48
|
+
dataUrlCondition: {
|
|
49
|
+
maxSize: 1000,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
.generator({
|
|
53
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
54
|
+
});
|
|
43
55
|
rule
|
|
44
56
|
.oneOf('fallback')
|
|
45
|
-
.exclude.add(
|
|
57
|
+
.exclude.add(/^$/) /* handle data: resources */
|
|
58
|
+
.add(/\.(js|mjs|jsx|ts|tsx)$/)
|
|
46
59
|
.add(/\.(css|less|sass|scss|stylus)$/)
|
|
47
60
|
.add(/\.html$/)
|
|
48
61
|
.add(/\.json$/)
|
package/dist/config/config.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ interface IOpts {
|
|
|
4
4
|
cwd: string;
|
|
5
5
|
env: Env;
|
|
6
6
|
entry: Record<string, string>;
|
|
7
|
+
extraBabelPresets?: any[];
|
|
7
8
|
extraBabelPlugins?: any[];
|
|
9
|
+
babelPreset?: any;
|
|
10
|
+
chainWebpack?: Function;
|
|
11
|
+
modifyWebpackConfig?: Function;
|
|
8
12
|
hash?: boolean;
|
|
9
13
|
hmr?: boolean;
|
|
10
14
|
staticPathPrefix?: string;
|
package/dist/config/config.js
CHANGED
|
@@ -47,7 +47,9 @@ function getConfig(opts) {
|
|
|
47
47
|
userConfig,
|
|
48
48
|
cwd: opts.cwd,
|
|
49
49
|
env: opts.env,
|
|
50
|
+
babelPreset: opts.babelPreset,
|
|
50
51
|
extraBabelPlugins: opts.extraBabelPlugins || [],
|
|
52
|
+
extraBabelPresets: opts.extraBabelPresets || [],
|
|
51
53
|
browsers: (0, browsersList_1.getBrowsersList)({
|
|
52
54
|
targets: userConfig.targets,
|
|
53
55
|
}),
|
|
@@ -79,7 +81,7 @@ function getConfig(opts) {
|
|
|
79
81
|
.path(absOutputPath)
|
|
80
82
|
.filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
|
|
81
83
|
.chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].js`)
|
|
82
|
-
.publicPath(userConfig.publicPath || '
|
|
84
|
+
.publicPath(userConfig.publicPath || 'auto')
|
|
83
85
|
.pathinfo(isDev || disableCompress);
|
|
84
86
|
// resolve
|
|
85
87
|
// prettier-ignore
|
|
@@ -109,6 +111,7 @@ function getConfig(opts) {
|
|
|
109
111
|
// experiments
|
|
110
112
|
config.experiments({
|
|
111
113
|
topLevelAwait: true,
|
|
114
|
+
outputModule: !!userConfig.esm,
|
|
112
115
|
});
|
|
113
116
|
// node polyfill
|
|
114
117
|
yield (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
|
|
@@ -145,6 +148,12 @@ function getConfig(opts) {
|
|
|
145
148
|
yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
|
|
146
149
|
}
|
|
147
150
|
// chain webpack
|
|
151
|
+
if (opts.chainWebpack) {
|
|
152
|
+
yield opts.chainWebpack(config, {
|
|
153
|
+
env: opts.env,
|
|
154
|
+
webpack: webpack_1.default,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
148
157
|
if (userConfig.chainWebpack) {
|
|
149
158
|
yield userConfig.chainWebpack(config, {
|
|
150
159
|
env: opts.env,
|
|
@@ -157,6 +166,12 @@ function getConfig(opts) {
|
|
|
157
166
|
webpackConfig = yield (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
|
|
158
167
|
webpackConfig,
|
|
159
168
|
});
|
|
169
|
+
if (opts.modifyWebpackConfig) {
|
|
170
|
+
webpackConfig = yield opts.modifyWebpackConfig(webpackConfig, {
|
|
171
|
+
env: opts.env,
|
|
172
|
+
webpack: webpack_1.default,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
160
175
|
return webpackConfig;
|
|
161
176
|
});
|
|
162
177
|
}
|
package/dist/config/cssRules.js
CHANGED
|
@@ -14,10 +14,10 @@ function addCSSRules(opts) {
|
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const { config, userConfig } = opts;
|
|
16
16
|
const rulesConfig = [
|
|
17
|
-
{ name: 'css', test: /\.css(\?.*)
|
|
17
|
+
{ name: 'css', test: /\.css(\?.*)?$/ },
|
|
18
18
|
{
|
|
19
19
|
name: 'less',
|
|
20
|
-
test: /\.less(\?.*)
|
|
20
|
+
test: /\.less(\?.*)?$/,
|
|
21
21
|
loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
|
|
22
22
|
loaderOptions: {
|
|
23
23
|
implementation: require.resolve('@umijs/bundler-webpack/compiled/less'),
|
|
@@ -26,7 +26,7 @@ function addCSSRules(opts) {
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
name: 'sass',
|
|
29
|
-
test: /\.(sass|scss)(\?.*)
|
|
29
|
+
test: /\.(sass|scss)(\?.*)?$/,
|
|
30
30
|
loader: require.resolve('@umijs/bundler-webpack/compiled/sass-loader'),
|
|
31
31
|
loaderOptions: userConfig.sassLoader || {},
|
|
32
32
|
},
|
|
@@ -8,17 +8,21 @@ 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) {
|
|
18
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
23
|
const { config, userConfig, cwd, env, name } = opts;
|
|
20
24
|
const isDev = opts.env === types_1.Env.development;
|
|
21
|
-
const useFastRefresh = isDev && userConfig.fastRefresh !== false && name
|
|
25
|
+
const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
|
|
22
26
|
const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
|
|
23
27
|
const srcRules = [
|
|
24
28
|
config.module
|
|
@@ -85,10 +89,9 @@ function addJavaScriptRules(opts) {
|
|
|
85
89
|
// : false,
|
|
86
90
|
targets: userConfig.targets,
|
|
87
91
|
presets: [
|
|
88
|
-
[
|
|
92
|
+
opts.babelPreset || [
|
|
89
93
|
require.resolve('@umijs/babel-preset-umi'),
|
|
90
94
|
{
|
|
91
|
-
env,
|
|
92
95
|
presetEnv: {},
|
|
93
96
|
presetReact: {},
|
|
94
97
|
presetTypeScript: {},
|
|
@@ -98,6 +101,7 @@ function addJavaScriptRules(opts) {
|
|
|
98
101
|
pluginAutoCSSModules: userConfig.autoCSSModules,
|
|
99
102
|
},
|
|
100
103
|
],
|
|
104
|
+
...opts.extraBabelPresets,
|
|
101
105
|
...(userConfig.extraBabelPresets || []).filter(Boolean),
|
|
102
106
|
],
|
|
103
107
|
plugins: [
|
|
@@ -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/config/svgRules.js
CHANGED
|
@@ -13,28 +13,15 @@ exports.addSVGRules = void 0;
|
|
|
13
13
|
function addSVGRules(opts) {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const { config, userConfig } = opts;
|
|
16
|
-
const { svgr, svgo } = userConfig;
|
|
16
|
+
const { svgr, svgo = {} } = userConfig;
|
|
17
17
|
if (svgr) {
|
|
18
|
-
// https://react-svgr.com/docs/webpack/#handle-svg-in-css-sass-or-less
|
|
19
|
-
// https://github.com/gregberge/svgr/issues/551#issuecomment-883073902
|
|
20
|
-
// https://github.com/webpack/webpack/issues/9309
|
|
21
18
|
const svgrRule = config.module.rule('svgr');
|
|
22
19
|
svgrRule
|
|
23
|
-
.test(/\.svg$/)
|
|
20
|
+
.test(/\.svg$/i)
|
|
24
21
|
.issuer(/\.[jt]sx?$/)
|
|
25
|
-
.type('javascript/auto')
|
|
26
|
-
.use('babel-loader')
|
|
27
|
-
.loader(require.resolve('@umijs/bundler-webpack/compiled/babel-loader'))
|
|
28
|
-
.end()
|
|
29
22
|
.use('svgr-loader')
|
|
30
23
|
.loader(require.resolve('@umijs/bundler-webpack/compiled/@svgr/webpack'))
|
|
31
|
-
.options(Object.assign(Object.assign({ svgoConfig: {
|
|
32
|
-
plugins: [{ removeViewBox: false }],
|
|
33
|
-
} }, svgr), { svgo }))
|
|
34
|
-
.end()
|
|
35
|
-
.use('url-loader')
|
|
36
|
-
.loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
|
|
37
|
-
.end();
|
|
24
|
+
.options(Object.assign(Object.assign({ svgoConfig: Object.assign({}, (svgo || {})) }, svgr), { svgo: !!svgo }));
|
|
38
25
|
}
|
|
39
26
|
if (svgo === false) {
|
|
40
27
|
const svgRule = config.module.rule('svg');
|
package/dist/dev.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ interface IOpts {
|
|
|
5
5
|
onDevCompileDone?: Function;
|
|
6
6
|
port?: number;
|
|
7
7
|
host?: string;
|
|
8
|
+
chainWebpack?: Function;
|
|
9
|
+
modifyWebpackConfig?: Function;
|
|
10
|
+
beforeBabelPlugins?: any[];
|
|
11
|
+
beforeBabelPresets?: any[];
|
|
12
|
+
extraBabelPlugins?: any[];
|
|
13
|
+
extraBabelPresets?: any[];
|
|
8
14
|
cwd: string;
|
|
9
15
|
config: IConfig;
|
|
10
16
|
entry: Record<string, string>;
|
package/dist/dev.js
CHANGED
|
@@ -21,16 +21,32 @@ 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
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const enableMFSU = opts.config.mfsu !== false;
|
|
27
|
+
let mfsu = null;
|
|
28
|
+
if (enableMFSU) {
|
|
29
|
+
mfsu = new mfsu_1.MFSU({
|
|
30
|
+
implementor: webpack_1.default,
|
|
31
|
+
buildDepWithESBuild: (_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
28
34
|
const webpackConfig = yield (0, config_1.getConfig)({
|
|
29
35
|
cwd: opts.cwd,
|
|
30
36
|
env: types_1.Env.development,
|
|
31
37
|
entry: opts.entry,
|
|
32
38
|
userConfig: opts.config,
|
|
33
|
-
extraBabelPlugins:
|
|
39
|
+
extraBabelPlugins: [
|
|
40
|
+
...(opts.beforeBabelPlugins || []),
|
|
41
|
+
...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
|
|
42
|
+
...(opts.extraBabelPlugins || []),
|
|
43
|
+
],
|
|
44
|
+
extraBabelPresets: [
|
|
45
|
+
...(opts.beforeBabelPresets || []),
|
|
46
|
+
...(opts.extraBabelPresets || []),
|
|
47
|
+
],
|
|
48
|
+
chainWebpack: opts.chainWebpack,
|
|
49
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
34
50
|
hmr: true,
|
|
35
51
|
analyze: process.env.ANALYZE,
|
|
36
52
|
});
|
|
@@ -43,13 +59,13 @@ function dev(opts) {
|
|
|
43
59
|
staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
|
|
44
60
|
name: constants_1.MFSU_NAME,
|
|
45
61
|
});
|
|
46
|
-
(
|
|
62
|
+
(_b = webpackConfig.resolve).alias || (_b.alias = {});
|
|
47
63
|
// TODO: REMOVE ME
|
|
48
64
|
['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
|
|
49
65
|
// @ts-ignore
|
|
50
66
|
webpackConfig.resolve.alias[dep] = require.resolve(dep);
|
|
51
67
|
});
|
|
52
|
-
mfsu.setWebpackConfig({
|
|
68
|
+
mfsu === null || mfsu === void 0 ? void 0 : mfsu.setWebpackConfig({
|
|
53
69
|
config: webpackConfig,
|
|
54
70
|
depConfig: depConfig,
|
|
55
71
|
});
|
|
@@ -58,7 +74,7 @@ function dev(opts) {
|
|
|
58
74
|
userConfig: opts.config,
|
|
59
75
|
cwd: opts.cwd,
|
|
60
76
|
beforeMiddlewares: [
|
|
61
|
-
...mfsu.getMiddlewares(),
|
|
77
|
+
...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getMiddlewares()) || []),
|
|
62
78
|
...(opts.beforeMiddlewares || []),
|
|
63
79
|
],
|
|
64
80
|
port: opts.port,
|
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(
|
|
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;
|
package/dist/server/server.js
CHANGED
|
@@ -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) => {
|
package/dist/server/ws.d.ts
CHANGED
package/dist/server/ws.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createWebSocketServer = void 0;
|
|
7
7
|
const utils_1 = require("@umijs/utils");
|
|
8
|
-
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
const ws_1 = __importDefault(require("../../compiled/ws"));
|
|
9
9
|
function createWebSocketServer(server) {
|
|
10
10
|
const wss = new ws_1.default.Server({
|
|
11
11
|
noServer: true,
|
|
@@ -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[];
|