@rsbuild/webpack 0.0.9 → 0.0.13
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/webpack-manifest-plugin/types/helpers.d.ts +1 -1
- package/compiled/webpack-manifest-plugin/types/hooks.d.ts +1 -1
- package/dist/config/defaults.js +1 -4
- package/dist/core/createContext.js +0 -4
- package/dist/core/devMiddleware.js +6 -6
- package/dist/core/initConfigs.d.ts +2 -2
- package/dist/core/initConfigs.js +1 -2
- package/dist/core/webpackConfig.js +7 -8
- package/dist/plugins/babel.js +5 -11
- package/dist/plugins/minimize.js +5 -2
- package/dist/plugins/moduleScopes.d.ts +2 -2
- package/dist/plugins/react.d.ts +2 -0
- package/dist/plugins/react.js +96 -0
- package/dist/plugins/tsLoader.js +54 -56
- package/dist/shared/plugin.js +1 -2
- package/dist/types/config/index.d.ts +6 -14
- package/dist/types/config/index.js +0 -10
- package/dist/types/config/security.d.ts +3 -3
- package/dist/types/config/source.d.ts +4 -13
- package/dist/types/config/tools.d.ts +15 -18
- package/dist/types/context.d.ts +0 -2
- package/dist/types/hooks.d.ts +7 -2
- package/dist/types/thirdParty/index.d.ts +0 -2
- package/package.json +32 -29
- package/dist/config/validate/dev.d.ts +0 -3
- package/dist/config/validate/dev.js +0 -29
- package/dist/config/validate/experiments.d.ts +0 -3
- package/dist/config/validate/experiments.js +0 -29
- package/dist/config/validate/html.d.ts +0 -3
- package/dist/config/validate/html.js +0 -29
- package/dist/config/validate/index.d.ts +0 -4
- package/dist/config/validate/index.js +0 -52
- package/dist/config/validate/output.d.ts +0 -3
- package/dist/config/validate/output.js +0 -37
- package/dist/config/validate/performance.d.ts +0 -3
- package/dist/config/validate/performance.js +0 -47
- package/dist/config/validate/security.d.ts +0 -4
- package/dist/config/validate/security.js +0 -38
- package/dist/config/validate/source.d.ts +0 -3
- package/dist/config/validate/source.js +0 -34
- package/dist/config/validate/tools.d.ts +0 -3
- package/dist/config/validate/tools.js +0 -57
- package/dist/exports/HtmlWebpackPlugin.d.ts +0 -2
- package/dist/exports/HtmlWebpackPlugin.js +0 -35
- package/dist/plugins/pug.d.ts +0 -2
- package/dist/plugins/pug.js +0 -52
- package/dist/types/config/dev.d.ts +0 -3
- package/dist/types/config/dev.js +0 -16
- package/dist/types/config/experiments.d.ts +0 -3
- package/dist/types/config/experiments.js +0 -16
- package/dist/types/config/html.d.ts +0 -3
- package/dist/types/config/html.js +0 -16
- package/dist/types/config/output.d.ts +0 -9
- package/dist/types/config/output.js +0 -16
- package/dist/types/config/performance.d.ts +0 -3
- package/dist/types/config/performance.js +0 -16
- package/dist/types/thirdParty/CopyWebpackPlugin.d.ts +0 -62
- package/dist/types/thirdParty/CopyWebpackPlugin.js +0 -16
- package/dist/webpackLoaders/pugLoader.d.ts +0 -3
- package/dist/webpackLoaders/pugLoader.js +0 -44
package/dist/config/defaults.js
CHANGED
|
@@ -33,10 +33,7 @@ const createDefaultConfig = () => ({
|
|
|
33
33
|
pluginOptions: {}
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
-
source:
|
|
37
|
-
...(0, import_shared.getDefaultSourceConfig)(),
|
|
38
|
-
define: {}
|
|
39
|
-
},
|
|
36
|
+
source: (0, import_shared.getDefaultSourceConfig)(),
|
|
40
37
|
output: (0, import_shared.getDefaultOutputConfig)(),
|
|
41
38
|
security: {
|
|
42
39
|
...(0, import_shared.getDefaultSecurityConfig)(),
|
|
@@ -25,7 +25,6 @@ module.exports = __toCommonJS(createContext_exports);
|
|
|
25
25
|
var import_path = require("path");
|
|
26
26
|
var import_shared = require("@rsbuild/shared");
|
|
27
27
|
var import_initHooks = require("./initHooks");
|
|
28
|
-
var import_validate = require("../config/validate");
|
|
29
28
|
var import_defaults = require("../config/defaults");
|
|
30
29
|
function createPrimaryContext(options, userRsbuildConfig) {
|
|
31
30
|
const rsbuildConfig = (0, import_defaults.withDefaultConfig)(userRsbuildConfig);
|
|
@@ -34,18 +33,15 @@ function createPrimaryContext(options, userRsbuildConfig) {
|
|
|
34
33
|
rsbuildConfig.output,
|
|
35
34
|
"webpack"
|
|
36
35
|
);
|
|
37
|
-
const configValidatingTask = Promise.resolve();
|
|
38
36
|
return {
|
|
39
37
|
...context,
|
|
40
38
|
hooks: (0, import_initHooks.initHooks)(),
|
|
41
|
-
configValidatingTask,
|
|
42
39
|
config: { ...rsbuildConfig },
|
|
43
40
|
originalConfig: userRsbuildConfig
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
43
|
async function createContext(options, rsbuildConfig) {
|
|
47
44
|
(0, import_shared.debug)("create context");
|
|
48
|
-
await (0, import_validate.validateRsbuildConfig)(rsbuildConfig);
|
|
49
45
|
const ctx = createPrimaryContext(options, rsbuildConfig);
|
|
50
46
|
const tsconfigPath = (0, import_path.join)(ctx.rootPath, import_shared.TS_CONFIG_FILE);
|
|
51
47
|
if (await (0, import_shared.isFileExists)(tsconfigPath)) {
|
|
@@ -35,15 +35,15 @@ var import_webpack_dev_middleware = __toESM(require("@rsbuild/shared/webpack-dev
|
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
36
|
const applyHMREntry = (compiler, clientPath) => {
|
|
37
37
|
const applyEntry = (clientEntry, compiler2) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if ((0, import_shared.isClientCompiler)(compiler2)) {
|
|
39
|
+
new compiler2.webpack.EntryPlugin(compiler2.context, clientEntry, {
|
|
40
|
+
name: void 0
|
|
41
|
+
}).apply(compiler2);
|
|
42
|
+
}
|
|
41
43
|
};
|
|
42
44
|
if (compiler.compilers) {
|
|
43
45
|
compiler.compilers.forEach((target) => {
|
|
44
|
-
|
|
45
|
-
applyEntry(clientPath, target);
|
|
46
|
-
}
|
|
46
|
+
applyEntry(clientPath, target);
|
|
47
47
|
});
|
|
48
48
|
} else {
|
|
49
49
|
applyEntry(clientPath, compiler);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PluginStore, type CreateRsbuildOptions } from '@rsbuild/shared';
|
|
2
|
-
import type { Context } from '../types';
|
|
2
|
+
import type { Context, WebpackConfig } from '../types';
|
|
3
3
|
export type InitConfigsOptions = {
|
|
4
4
|
context: Context;
|
|
5
5
|
pluginStore: PluginStore;
|
|
@@ -10,5 +10,5 @@ export declare function initConfigs({
|
|
|
10
10
|
pluginStore,
|
|
11
11
|
rsbuildOptions
|
|
12
12
|
}: InitConfigsOptions): Promise<{
|
|
13
|
-
webpackConfigs:
|
|
13
|
+
webpackConfigs: WebpackConfig[];
|
|
14
14
|
}>;
|
package/dist/core/initConfigs.js
CHANGED
|
@@ -39,14 +39,13 @@ async function initConfigs({
|
|
|
39
39
|
pluginStore,
|
|
40
40
|
rsbuildOptions
|
|
41
41
|
}) {
|
|
42
|
-
await context.configValidatingTask;
|
|
43
42
|
await (0, import_shared.initPlugins)({
|
|
44
43
|
pluginAPI: context.pluginAPI,
|
|
45
44
|
pluginStore
|
|
46
45
|
});
|
|
47
46
|
await modifyRsbuildConfig(context);
|
|
48
47
|
context.normalizedConfig = (0, import_normalize.normalizeConfig)(context.config);
|
|
49
|
-
const targets = (0, import_shared.
|
|
48
|
+
const targets = (0, import_shared.castArray)(rsbuildOptions.target);
|
|
50
49
|
const webpackConfigs = await Promise.all(
|
|
51
50
|
targets.map((target) => (0, import_webpackConfig.generateWebpackConfig)({ target, context }))
|
|
52
51
|
);
|
|
@@ -32,7 +32,6 @@ __export(webpackConfig_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(webpackConfig_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
var import_lodash = require("lodash");
|
|
36
35
|
var import_shared2 = require("../shared");
|
|
37
36
|
async function modifyWebpackChain(context, utils, chain) {
|
|
38
37
|
var _a;
|
|
@@ -42,7 +41,7 @@ async function modifyWebpackChain(context, utils, chain) {
|
|
|
42
41
|
utils
|
|
43
42
|
);
|
|
44
43
|
if ((_a = context.config.tools) == null ? void 0 : _a.webpackChain) {
|
|
45
|
-
(0, import_shared.
|
|
44
|
+
(0, import_shared.castArray)(context.config.tools.webpackChain).forEach((item) => {
|
|
46
45
|
item(modifiedChain, utils);
|
|
47
46
|
});
|
|
48
47
|
}
|
|
@@ -69,7 +68,7 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
|
|
|
69
68
|
}
|
|
70
69
|
async function getChainUtils(target) {
|
|
71
70
|
const { default: webpack } = await Promise.resolve().then(() => __toESM(require("webpack")));
|
|
72
|
-
const { default:
|
|
71
|
+
const { default: HtmlPlugin } = await Promise.resolve().then(() => __toESM(require("html-webpack-plugin")));
|
|
73
72
|
const nodeEnv = process.env.NODE_ENV;
|
|
74
73
|
const nameMap = {
|
|
75
74
|
web: "client",
|
|
@@ -88,8 +87,8 @@ async function getChainUtils(target) {
|
|
|
88
87
|
isWebWorker: target === "web-worker",
|
|
89
88
|
CHAIN_ID: import_shared.CHAIN_ID,
|
|
90
89
|
getCompiledPath: import_shared2.getCompiledPath,
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
HtmlPlugin,
|
|
91
|
+
HtmlWebpackPlugin: HtmlPlugin
|
|
93
92
|
};
|
|
94
93
|
}
|
|
95
94
|
async function getConfigUtils(config, chainUtils) {
|
|
@@ -98,7 +97,7 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
98
97
|
...chainUtils,
|
|
99
98
|
mergeConfig: merge,
|
|
100
99
|
addRules(rules) {
|
|
101
|
-
const ruleArr = (0,
|
|
100
|
+
const ruleArr = (0, import_shared.castArray)(rules);
|
|
102
101
|
if (!config.module) {
|
|
103
102
|
config.module = {};
|
|
104
103
|
}
|
|
@@ -108,14 +107,14 @@ async function getConfigUtils(config, chainUtils) {
|
|
|
108
107
|
config.module.rules.unshift(...ruleArr);
|
|
109
108
|
},
|
|
110
109
|
prependPlugins(plugins) {
|
|
111
|
-
const pluginArr = (0,
|
|
110
|
+
const pluginArr = (0, import_shared.castArray)(plugins);
|
|
112
111
|
if (!config.plugins) {
|
|
113
112
|
config.plugins = [];
|
|
114
113
|
}
|
|
115
114
|
config.plugins.unshift(...pluginArr);
|
|
116
115
|
},
|
|
117
116
|
appendPlugins(plugins) {
|
|
118
|
-
const pluginArr = (0,
|
|
117
|
+
const pluginArr = (0, import_shared.castArray)(plugins);
|
|
119
118
|
if (!config.plugins) {
|
|
120
119
|
config.plugins = [];
|
|
121
120
|
}
|
package/dist/plugins/babel.js
CHANGED
|
@@ -36,6 +36,7 @@ var import_lodash = __toESM(require("lodash"));
|
|
|
36
36
|
var import_web = require("@rsbuild/babel-preset/web");
|
|
37
37
|
var import_node = require("@rsbuild/babel-preset/node");
|
|
38
38
|
var import_shared = require("@rsbuild/shared");
|
|
39
|
+
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
39
40
|
var import_shared2 = require("../shared");
|
|
40
41
|
const getUseBuiltIns = (config) => {
|
|
41
42
|
const { polyfill } = config.output;
|
|
@@ -48,14 +49,7 @@ const pluginBabel = () => ({
|
|
|
48
49
|
name: "plugin-babel",
|
|
49
50
|
setup(api) {
|
|
50
51
|
api.modifyBundlerChain(
|
|
51
|
-
async (chain, {
|
|
52
|
-
CHAIN_ID,
|
|
53
|
-
target,
|
|
54
|
-
isProd,
|
|
55
|
-
isServer,
|
|
56
|
-
isServiceWorker,
|
|
57
|
-
getCompiledPath: getCompiledPath2
|
|
58
|
-
}) => {
|
|
52
|
+
async (chain, { CHAIN_ID, target, isProd, isServer, isServiceWorker }) => {
|
|
59
53
|
const config = api.getNormalizedConfig();
|
|
60
54
|
const browserslist = await (0, import_shared.getBrowserslistWithDefault)(
|
|
61
55
|
api.context.rootPath,
|
|
@@ -102,7 +96,7 @@ const pluginBabel = () => ({
|
|
|
102
96
|
baseBabelConfig,
|
|
103
97
|
config2.tools.babel,
|
|
104
98
|
{
|
|
105
|
-
...(0,
|
|
99
|
+
...(0, import_plugin_babel.getBabelUtils)(baseBabelConfig),
|
|
106
100
|
...babelUtils
|
|
107
101
|
}
|
|
108
102
|
);
|
|
@@ -133,11 +127,11 @@ const pluginBabel = () => ({
|
|
|
133
127
|
includes,
|
|
134
128
|
excludes
|
|
135
129
|
});
|
|
136
|
-
rule.test(useTsLoader ? import_shared.JS_REGEX : (0, import_shared.mergeRegex)(import_shared.JS_REGEX, import_shared.TS_REGEX)).use(CHAIN_ID.USE.BABEL).loader(
|
|
130
|
+
rule.test(useTsLoader ? import_shared.JS_REGEX : (0, import_shared.mergeRegex)(import_shared.JS_REGEX, import_shared.TS_REGEX)).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
|
|
137
131
|
if (config.source.compileJsDataURI) {
|
|
138
132
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
139
133
|
or: ["text/javascript", "application/javascript"]
|
|
140
|
-
}).use(CHAIN_ID.USE.BABEL).loader(
|
|
134
|
+
}).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(import_lodash.default.cloneDeep(babelOptions));
|
|
141
135
|
}
|
|
142
136
|
(0, import_shared.addCoreJsEntry)({ chain, config, isServer, isServiceWorker });
|
|
143
137
|
}
|
package/dist/plugins/minimize.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(minimize_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(minimize_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
var import_plugin_css_minimizer = require("@rsbuild/plugin-css-minimizer");
|
|
35
36
|
async function applyJSMinimizer(chain, config) {
|
|
36
37
|
const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
|
|
37
38
|
const finalOptions = await (0, import_shared.getJSMinifyOptions)(config);
|
|
@@ -44,13 +45,15 @@ async function applyJSMinimizer(chain, config) {
|
|
|
44
45
|
const pluginMinimize = () => ({
|
|
45
46
|
name: "plugin-minimize",
|
|
46
47
|
setup(api) {
|
|
47
|
-
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
48
|
+
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID: CHAIN_ID2 }) => {
|
|
48
49
|
const config = api.getNormalizedConfig();
|
|
49
50
|
const isMinimize = isProd && !config.output.disableMinimize;
|
|
50
51
|
chain.optimization.minimize(isMinimize);
|
|
51
52
|
if (isMinimize) {
|
|
52
53
|
await applyJSMinimizer(chain, config);
|
|
53
|
-
await (0,
|
|
54
|
+
await (0, import_plugin_css_minimizer.applyCSSMinimizer)(chain, CHAIN_ID2, {
|
|
55
|
+
pluginOptions: config.tools.minifyCss
|
|
56
|
+
});
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
59
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ChainedConfig
|
|
2
|
-
import type { RsbuildPlugin } from '../types';
|
|
1
|
+
import { type ChainedConfig } from '@rsbuild/shared';
|
|
2
|
+
import type { RsbuildPlugin, ModuleScopes } from '../types';
|
|
3
3
|
export declare const isPrimitiveScope: (items: unknown[]) => items is (string | RegExp)[];
|
|
4
4
|
export declare const applyScopeChain: (defaults: ModuleScopes, options: ChainedConfig<ModuleScopes>) => ModuleScopes;
|
|
5
5
|
export declare const pluginModuleScopes: () => RsbuildPlugin;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var react_exports = {};
|
|
30
|
+
__export(react_exports, {
|
|
31
|
+
pluginReactWebpack: () => pluginReactWebpack
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(react_exports);
|
|
34
|
+
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
const pluginReactWebpack = () => ({
|
|
36
|
+
name: "plugin-react-webpack",
|
|
37
|
+
setup(api) {
|
|
38
|
+
api.modifyRsbuildConfig(async (config, { mergeRsbuildConfig }) => {
|
|
39
|
+
const babelConfig = {
|
|
40
|
+
tools: {
|
|
41
|
+
babel(_, { addPresets, addPlugins }) {
|
|
42
|
+
const isNewJsx = (0, import_shared.isBeyondReact17)(api.context.rootPath);
|
|
43
|
+
const presetReactOptions = {
|
|
44
|
+
development: !(0, import_shared.isProd)(),
|
|
45
|
+
// Will use the native built-in instead of trying to polyfill
|
|
46
|
+
useBuiltIns: true,
|
|
47
|
+
useSpread: false,
|
|
48
|
+
runtime: isNewJsx ? "automatic" : "classic"
|
|
49
|
+
};
|
|
50
|
+
addPresets([
|
|
51
|
+
[require.resolve("@babel/preset-react"), presetReactOptions]
|
|
52
|
+
]);
|
|
53
|
+
if ((0, import_shared.isProd)()) {
|
|
54
|
+
addPlugins([
|
|
55
|
+
[
|
|
56
|
+
require.resolve("babel-plugin-transform-react-remove-prop-types"),
|
|
57
|
+
{ removeImport: true }
|
|
58
|
+
]
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return mergeRsbuildConfig(babelConfig, config);
|
|
65
|
+
});
|
|
66
|
+
api.modifyWebpackChain(async (chain, utils) => {
|
|
67
|
+
const config = api.getNormalizedConfig();
|
|
68
|
+
if (!(0, import_shared.isUsingHMR)(config, utils)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const { CHAIN_ID } = utils;
|
|
72
|
+
const { default: ReactFastRefreshPlugin } = await Promise.resolve().then(() => __toESM(require("@pmmmwh/react-refresh-webpack-plugin")));
|
|
73
|
+
const useTsLoader = Boolean(config.tools.tsLoader);
|
|
74
|
+
const rule = useTsLoader ? chain.module.rule(CHAIN_ID.RULE.TS) : chain.module.rule(CHAIN_ID.RULE.JS);
|
|
75
|
+
if (rule.uses.get(CHAIN_ID.USE.BABEL)) {
|
|
76
|
+
rule.use(CHAIN_ID.USE.BABEL).tap((options) => ({
|
|
77
|
+
...options,
|
|
78
|
+
plugins: [
|
|
79
|
+
...options.plugins || [],
|
|
80
|
+
[require.resolve("react-refresh/babel"), { skipEnvCheck: true }]
|
|
81
|
+
]
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).use(ReactFastRefreshPlugin, [
|
|
85
|
+
{
|
|
86
|
+
overlay: false,
|
|
87
|
+
exclude: [/node_modules/]
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
pluginReactWebpack
|
|
96
|
+
});
|
package/dist/plugins/tsLoader.js
CHANGED
|
@@ -32,70 +32,68 @@ __export(tsLoader_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(tsLoader_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
-
var
|
|
35
|
+
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
36
36
|
var import_web = require("@rsbuild/babel-preset/web");
|
|
37
37
|
var import_babel = require("./babel");
|
|
38
38
|
const pluginTsLoader = () => {
|
|
39
39
|
return {
|
|
40
40
|
name: "plugin-ts-loader",
|
|
41
41
|
setup(api) {
|
|
42
|
-
api.modifyWebpackChain(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
api.modifyWebpackChain(async (chain, { target, CHAIN_ID }) => {
|
|
43
|
+
const config = api.getNormalizedConfig();
|
|
44
|
+
if (!config.tools.tsLoader) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const { rootPath } = api.context;
|
|
48
|
+
const browserslist = await (0, import_shared.getBrowserslistWithDefault)(
|
|
49
|
+
rootPath,
|
|
50
|
+
config,
|
|
51
|
+
target
|
|
52
|
+
);
|
|
53
|
+
const baseBabelConfig = (0, import_web.getBabelConfigForWeb)({
|
|
54
|
+
presetEnv: {
|
|
55
|
+
targets: browserslist,
|
|
56
|
+
useBuiltIns: (0, import_babel.getUseBuiltIns)(config)
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
includes.push(...import_lodash.default.castArray(items));
|
|
71
|
-
},
|
|
72
|
-
addExcludes(items) {
|
|
73
|
-
excludes.push(...import_lodash.default.castArray(items));
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const tsLoaderOptions = (0, import_shared.mergeChainedOptions)(
|
|
77
|
-
{
|
|
78
|
-
compilerOptions: {
|
|
79
|
-
target: "esnext",
|
|
80
|
-
module: "esnext"
|
|
81
|
-
},
|
|
82
|
-
transpileOnly: true,
|
|
83
|
-
allowTsInNodeModules: true
|
|
58
|
+
});
|
|
59
|
+
const babelUtils = (0, import_plugin_babel.getBabelUtils)(baseBabelConfig);
|
|
60
|
+
const babelLoaderOptions = (0, import_shared.mergeChainedOptions)(
|
|
61
|
+
baseBabelConfig,
|
|
62
|
+
config.tools.babel,
|
|
63
|
+
babelUtils
|
|
64
|
+
);
|
|
65
|
+
const includes = [];
|
|
66
|
+
const excludes = [];
|
|
67
|
+
const tsLoaderUtils = {
|
|
68
|
+
addIncludes(items) {
|
|
69
|
+
includes.push(...(0, import_shared.castArray)(items));
|
|
70
|
+
},
|
|
71
|
+
addExcludes(items) {
|
|
72
|
+
excludes.push(...(0, import_shared.castArray)(items));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const tsLoaderOptions = (0, import_shared.mergeChainedOptions)(
|
|
76
|
+
{
|
|
77
|
+
compilerOptions: {
|
|
78
|
+
target: "esnext",
|
|
79
|
+
module: "esnext"
|
|
84
80
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
transpileOnly: true,
|
|
82
|
+
allowTsInNodeModules: true
|
|
83
|
+
},
|
|
84
|
+
config.tools.tsLoader,
|
|
85
|
+
tsLoaderUtils
|
|
86
|
+
);
|
|
87
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.TS);
|
|
88
|
+
(0, import_shared.applyScriptCondition)({
|
|
89
|
+
rule,
|
|
90
|
+
config,
|
|
91
|
+
context: api.context,
|
|
92
|
+
includes,
|
|
93
|
+
excludes
|
|
94
|
+
});
|
|
95
|
+
rule.test(import_shared.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelLoaderOptions).end().use(CHAIN_ID.USE.TS).loader(require.resolve("ts-loader")).options(tsLoaderOptions);
|
|
96
|
+
});
|
|
99
97
|
}
|
|
100
98
|
};
|
|
101
99
|
};
|
package/dist/shared/plugin.js
CHANGED
|
@@ -66,9 +66,8 @@ const applyDefaultPlugins = (plugins) => {
|
|
|
66
66
|
(_b = plugins.cleanOutput) == null ? void 0 : _b.call(plugins),
|
|
67
67
|
Promise.resolve().then(() => __toESM(require("../plugins/hmr"))).then((m) => m.pluginHMR()),
|
|
68
68
|
plugins.svg(),
|
|
69
|
-
Promise.resolve().then(() => __toESM(require("../plugins/pug"))).then((m) => m.pluginPug()),
|
|
70
|
-
plugins.checkSyntax(),
|
|
71
69
|
Promise.resolve().then(() => __toESM(require("../plugins/copy"))).then((m) => m.pluginCopy()),
|
|
70
|
+
Promise.resolve().then(() => __toESM(require("../plugins/react"))).then((m) => m.pluginReactWebpack()),
|
|
72
71
|
plugins.font(),
|
|
73
72
|
plugins.image(),
|
|
74
73
|
plugins.media(),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { DeepReadonly } from '@rsbuild/shared';
|
|
2
|
-
import type { DevConfig, NormalizedDevConfig } from './dev';
|
|
3
|
-
import type { ExperimentsConfig, NormalizedExperimentsConfig } from './experiments';
|
|
4
|
-
import type { HtmlConfig, NormalizedHtmlConfig } from './html';
|
|
5
|
-
import type { NormalizedOutputConfig, OutputConfig } from './output';
|
|
6
|
-
import type { NormalizedPerformanceConfig, PerformanceConfig } from './performance';
|
|
7
2
|
import type { NormalizedSecurityConfig, SecurityConfig } from './security';
|
|
8
3
|
import type { NormalizedSourceConfig, SourceConfig } from './source';
|
|
9
4
|
import type { NormalizedToolsConfig, ToolsConfig } from './tools';
|
|
5
|
+
import type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig } from '@rsbuild/shared';
|
|
6
|
+
export type { DevConfig, HtmlConfig, OutputConfig, ExperimentsConfig, PerformanceConfig, NormalizedDevConfig, NormalizedHtmlConfig, NormalizedOutputConfig, NormalizedExperimentsConfig, NormalizedPerformanceConfig };
|
|
7
|
+
export * from './security';
|
|
8
|
+
export * from './source';
|
|
9
|
+
export * from './tools';
|
|
10
10
|
/** The Rsbuild config when using Webpack as the bundler */
|
|
11
11
|
export interface RsbuildConfig {
|
|
12
12
|
dev?: DevConfig;
|
|
@@ -27,12 +27,4 @@ export type NormalizedConfig = DeepReadonly<{
|
|
|
27
27
|
security: NormalizedSecurityConfig;
|
|
28
28
|
performance: NormalizedPerformanceConfig;
|
|
29
29
|
experiments: NormalizedExperimentsConfig;
|
|
30
|
-
}>;
|
|
31
|
-
export * from './dev';
|
|
32
|
-
export * from './experiments';
|
|
33
|
-
export * from './html';
|
|
34
|
-
export * from './output';
|
|
35
|
-
export * from './performance';
|
|
36
|
-
export * from './security';
|
|
37
|
-
export * from './source';
|
|
38
|
-
export * from './tools';
|
|
30
|
+
}>;
|
|
@@ -15,21 +15,11 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var config_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(config_exports);
|
|
18
|
-
__reExport(config_exports, require("./dev"), module.exports);
|
|
19
|
-
__reExport(config_exports, require("./experiments"), module.exports);
|
|
20
|
-
__reExport(config_exports, require("./html"), module.exports);
|
|
21
|
-
__reExport(config_exports, require("./output"), module.exports);
|
|
22
|
-
__reExport(config_exports, require("./performance"), module.exports);
|
|
23
18
|
__reExport(config_exports, require("./security"), module.exports);
|
|
24
19
|
__reExport(config_exports, require("./source"), module.exports);
|
|
25
20
|
__reExport(config_exports, require("./tools"), module.exports);
|
|
26
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
22
|
0 && (module.exports = {
|
|
28
|
-
...require("./dev"),
|
|
29
|
-
...require("./experiments"),
|
|
30
|
-
...require("./html"),
|
|
31
|
-
...require("./output"),
|
|
32
|
-
...require("./performance"),
|
|
33
23
|
...require("./security"),
|
|
34
24
|
...require("./source"),
|
|
35
25
|
...require("./tools")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { SriOptions,
|
|
2
|
-
export type SecurityConfig =
|
|
1
|
+
import type { SriOptions, SecurityConfig as BaseSecurityConfig, NormalizedSecurityConfig as BaseNormalizedSecurityConfig } from '@rsbuild/shared';
|
|
2
|
+
export type SecurityConfig = BaseSecurityConfig & {
|
|
3
3
|
/**
|
|
4
4
|
* Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML allows the browser to
|
|
5
5
|
* verify the integrity of the introduced resource, thus preventing tampering with the downloaded resource.
|
|
6
6
|
*/
|
|
7
7
|
sri?: SriOptions | boolean;
|
|
8
8
|
};
|
|
9
|
-
export type NormalizedSecurityConfig =
|
|
9
|
+
export type NormalizedSecurityConfig = BaseNormalizedSecurityConfig & Required<Pick<SecurityConfig, 'sri'>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChainedConfig, SourceConfig as BaseSourceConfig, NormalizedSourceConfig as BaseNormalizedSourceConfig } from '@rsbuild/shared';
|
|
2
|
+
export type ModuleScopes = Array<string | RegExp>;
|
|
2
3
|
export type TransformImport = {
|
|
3
4
|
libraryName: string;
|
|
4
5
|
libraryDirectory?: string;
|
|
@@ -9,27 +10,17 @@ export type TransformImport = {
|
|
|
9
10
|
customName?: ((member: string) => string | undefined) | string;
|
|
10
11
|
customStyleName?: ((member: string) => string | undefined) | string;
|
|
11
12
|
};
|
|
12
|
-
export interface SourceConfig extends
|
|
13
|
-
/**
|
|
14
|
-
* Replaces variables in your code with other values or expressions at compile time.
|
|
15
|
-
*/
|
|
16
|
-
define?: Record<string, any>;
|
|
13
|
+
export interface SourceConfig extends BaseSourceConfig {
|
|
17
14
|
/**
|
|
18
15
|
* Restrict importing paths. After configuring this option, all source files can only import code from
|
|
19
16
|
* the specific paths, and import code from other paths is not allowed.
|
|
20
17
|
*/
|
|
21
18
|
moduleScopes?: ChainedConfig<ModuleScopes>;
|
|
22
|
-
/**
|
|
23
|
-
* Configurare babel-plugin-import or swc-plugin-import or Rspack builtins plugin import
|
|
24
|
-
*/
|
|
25
|
-
transformImport?: false | TransformImport[];
|
|
26
19
|
}
|
|
27
|
-
export interface NormalizedSourceConfig extends
|
|
28
|
-
define: Record<string, any>;
|
|
20
|
+
export interface NormalizedSourceConfig extends BaseNormalizedSourceConfig {
|
|
29
21
|
/**
|
|
30
22
|
* Restrict importing paths. After configuring this option, all source files can only import code from
|
|
31
23
|
* the specific paths, and import code from other paths is not allowed.
|
|
32
24
|
*/
|
|
33
25
|
moduleScopes?: ChainedConfig<ModuleScopes>;
|
|
34
|
-
transformImport?: false | TransformImport[];
|
|
35
26
|
}
|