@rspack/core 0.0.0-20220909025136
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/CHANGELOG.md +51 -0
- package/README.md +1 -0
- package/bin.js +1 -0
- package/dist/bin/index.d.ts +1 -0
- package/dist/bin/index.js +32 -0
- package/dist/build.d.ts +1 -0
- package/dist/build.js +12 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +26 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +229 -0
- package/dist/server/index.d.ts +0 -0
- package/dist/server/index.js +0 -0
- package/example/basic.ts +71 -0
- package/example/react-example/index.html +12 -0
- package/example/react-example/package.json +17 -0
- package/example/react-example/rspack.config.json +13 -0
- package/example/react-example/src/app.jsx +44 -0
- package/example/react-example/src/base.css +9 -0
- package/example/react-example/src/button.jsx +3 -0
- package/example/react-example/src/dark.svg +1 -0
- package/example/react-example/src/data.json +5 -0
- package/example/react-example/src/file.jpg +0 -0
- package/example/react-example/src/file.png +0 -0
- package/example/react-example/src/file.svg +1 -0
- package/example/react-example/src/foo.css +3 -0
- package/example/react-example/src/index.html +32 -0
- package/example/react-example/src/index.js +1 -0
- package/example/react-example/src/light.svg +48 -0
- package/example/react-example/src/logo.svg +18 -0
- package/example/react-with-sass.ts +28 -0
- package/lib/bin/index.d.ts +1 -0
- package/lib/bin/index.js +32 -0
- package/lib/build.d.ts +1 -0
- package/lib/build.js +12 -0
- package/lib/config/builtins.d.ts +3 -0
- package/lib/config/builtins.js +2 -0
- package/lib/config/context.d.ts +2 -0
- package/lib/config/context.js +2 -0
- package/lib/config/define.d.ts +2 -0
- package/lib/config/define.js +2 -0
- package/lib/config/dev.d.ts +17 -0
- package/lib/config/dev.js +17 -0
- package/lib/config/entry.d.ts +2 -0
- package/lib/config/entry.js +2 -0
- package/lib/config/external.d.ts +2 -0
- package/lib/config/external.js +2 -0
- package/lib/config/index.d.ts +45 -0
- package/lib/config/index.js +37 -0
- package/lib/config/mode.d.ts +2 -0
- package/lib/config/mode.js +2 -0
- package/lib/config/module.d.ts +64 -0
- package/lib/config/module.js +121 -0
- package/lib/config/output.d.ts +17 -0
- package/lib/config/output.js +14 -0
- package/lib/config/plugin.d.ts +5 -0
- package/lib/config/plugin.js +2 -0
- package/lib/config/resolve.d.ts +6 -0
- package/lib/config/resolve.js +2 -0
- package/lib/config/target.d.ts +5 -0
- package/lib/config/target.js +13 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.js +154 -0
- package/lib/server/index.d.ts +0 -0
- package/lib/server/index.js +0 -0
- package/package.json +49 -0
- package/src/bin/index.ts +36 -0
- package/src/build.ts +8 -0
- package/src/config/builtins.ts +5 -0
- package/src/config/context.ts +3 -0
- package/src/config/define.ts +3 -0
- package/src/config/dev.ts +32 -0
- package/src/config/entry.ts +3 -0
- package/src/config/external.ts +3 -0
- package/src/config/index.ts +80 -0
- package/src/config/mode.ts +2 -0
- package/src/config/module.ts +240 -0
- package/src/config/output.ts +29 -0
- package/src/config/plugin.ts +6 -0
- package/src/config/resolve.ts +6 -0
- package/src/config/target.ts +29 -0
- package/src/index.ts +140 -0
- package/src/server/index.ts +0 -0
- package/tests/config.test.ts +40 -0
- package/tsconfig.json +14 -0
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 600"><title>icon-square-small</title><path fill="#FFF" d="M300 .1L565 150v299.9L300 599.8 35 449.9V150z"/><path fill="#8ED6FB" d="M517.7 439.5L308.8 557.8v-92L439 394.1l78.7 45.4zm14.3-12.9V179.4l-76.4 44.1v159l76.4 44.1zM81.5 439.5l208.9 118.2v-92l-130.2-71.6-78.7 45.4zm-14.3-12.9V179.4l76.4 44.1v159l-76.4 44.1zm8.9-263.2L290.4 42.2v89l-137.3 75.5-1.1.6-75.9-43.9zm446.9 0L308.8 42.2v89L446 206.8l1.1.6 75.9-44z"/><path fill="#1C78C0" d="M290.4 444.8L162 374.1V234.2l128.4 74.1v136.5zm18.4 0l128.4-70.6v-140l-128.4 74.1v136.5zM299.6 303zm-129-85l129-70.9L428.5 218l-128.9 74.4-129-74.4z"/></svg>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<title>React App</title>
|
|
7
|
+
<script>
|
|
8
|
+
process = {
|
|
9
|
+
env: 'production'
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
<script src="./runtime.js"></script>
|
|
13
|
+
<link rel="stylesheet" href="./main.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
18
|
+
<div id="root"></div>
|
|
19
|
+
<!--
|
|
20
|
+
This HTML file is a template.
|
|
21
|
+
If you open it directly in the browser, you will see an empty page.
|
|
22
|
+
|
|
23
|
+
You can add webfonts, meta tags, or analytics to this file.
|
|
24
|
+
The build step will place the bundled scripts into the <body> tag.
|
|
25
|
+
|
|
26
|
+
To begin the development, run `npm start` or `yarn start`.
|
|
27
|
+
To create a production bundle, use `npm run build` or `yarn build`.
|
|
28
|
+
-->
|
|
29
|
+
</body>
|
|
30
|
+
<script src="./main.js"></script>
|
|
31
|
+
|
|
32
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./app.jsx";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
|
|
4
|
+
y="0px" viewBox="0 0 22 22" style="enable-background:new 0 0 22 22;" xml:space="preserve">
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
.st1 {
|
|
7
|
+
fill: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
body {
|
|
11
|
+
background: deepskyblue;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
<title>编组 5备份</title>
|
|
15
|
+
<desc>Created with Sketch.</desc>
|
|
16
|
+
<g id="组件页-Web端-_xD83E__xDD1F_">
|
|
17
|
+
<g id="暗黑模式" transform="translate(2.500000, 2.500000)">
|
|
18
|
+
<g id="编组-12">
|
|
19
|
+
<g id="编组-8">
|
|
20
|
+
<g id="编组-7" transform="translate(7.285714, 0.000000)">
|
|
21
|
+
</g>
|
|
22
|
+
|
|
23
|
+
<g id="编组-7备份"
|
|
24
|
+
transform="translate(8.500000, 8.500000) rotate(-270.000000) translate(-8.500000, -8.500000) translate(7.285714, 0.000000)">
|
|
25
|
+
</g>
|
|
26
|
+
|
|
27
|
+
<g id="编组-7备份-2"
|
|
28
|
+
transform="translate(8.500000, 8.500000) rotate(-225.000000) translate(-8.500000, -8.500000) translate(7.285714, 0.000000)">
|
|
29
|
+
</g>
|
|
30
|
+
|
|
31
|
+
<g id="编组-7备份-3"
|
|
32
|
+
transform="translate(8.500000, 8.500000) rotate(-315.000000) translate(-8.500000, -8.500000) translate(7.285714, 0.000000)">
|
|
33
|
+
</g>
|
|
34
|
+
</g>
|
|
35
|
+
</g>
|
|
36
|
+
<path id="椭圆形" class="st0" d="M8.5,11.5c1.7,0,3-1.4,3-3s-1.4-3-3-3s-3,1.4-3,3S6.8,11.5,8.5,11.5z" />
|
|
37
|
+
<rect id="矩形" x="7.3" class="st0" width="2.4" height="2.4" />
|
|
38
|
+
<rect id="矩形备份-2" x="7.3" y="14.6" class="st0" width="2.4" height="2.4" />
|
|
39
|
+
<polygon id="矩形_1_" class="st0" points="17,7.3 17,9.7 14.6,9.7 14.6,7.3 " />
|
|
40
|
+
<polygon id="矩形备份-2_1_" class="st0" points="2.4,7.3 2.4,9.7 0,9.7 0,7.3 " />
|
|
41
|
+
<polygon id="矩形_2_" class="st0" points="15.4,13.7 13.7,15.4 11.9,13.7 13.7,11.9 " />
|
|
42
|
+
<polygon id="矩形备份-2_2_" class="st0" points="5.1,3.3 3.3,5.1 1.6,3.3 3.3,1.6 " />
|
|
43
|
+
<polygon id="矩形_3_" class="st0" points="13.7,1.6 15.4,3.3 13.7,5.1 11.9,3.3 " />
|
|
44
|
+
<polygon id="矩形备份-2_3_" class="st0" points="3.3,11.9 5.1,13.7 3.3,15.4 1.6,13.7 " />
|
|
45
|
+
</g>
|
|
46
|
+
</g>
|
|
47
|
+
<rect x="0" class="st1" width="22" height="22" />
|
|
48
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg width="33" height="33" viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g clip-path="url(#clip0)">
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd"
|
|
4
|
+
d="M5.37754 16.9795L12.7498 9.43027C14.7163 7.41663 17.9428 7.37837 19.9564 9.34482C19.9852 9.37297 20.0137 9.40145 20.0418 9.43027L20.1221 9.51243C22.1049 11.5429 22.1049 14.7847 20.1221 16.8152L12.7498 24.3644C10.7834 26.378 7.55686 26.4163 5.54322 24.4498C5.5144 24.4217 5.48592 24.3932 5.45777 24.3644L5.37754 24.2822C3.39468 22.2518 3.39468 19.0099 5.37754 16.9795Z"
|
|
5
|
+
fill="#12D2AC" />
|
|
6
|
+
<path fill-rule="evenodd" clip-rule="evenodd"
|
|
7
|
+
d="M20.0479 9.43034L27.3399 16.8974C29.3674 18.9735 29.3674 22.2883 27.3399 24.3644C25.3735 26.3781 22.147 26.4163 20.1333 24.4499C20.1045 24.4217 20.076 24.3933 20.0479 24.3644L12.7558 16.8974C10.7284 14.8213 10.7284 11.5065 12.7558 9.43034C14.7223 7.4167 17.9488 7.37844 19.9624 9.34489C19.9912 9.37304 20.0197 9.40152 20.0479 9.43034Z"
|
|
8
|
+
fill="#307AF2" />
|
|
9
|
+
<path fill-rule="evenodd" clip-rule="evenodd"
|
|
10
|
+
d="M20.1321 9.52163L23.6851 13.1599L16.3931 20.627L9.10103 13.1599L12.6541 9.52163C14.6707 7.45664 17.9794 7.4174 20.0444 9.434C20.074 9.46286 20.1032 9.49207 20.1321 9.52163Z"
|
|
11
|
+
fill="#0057FE" />
|
|
12
|
+
</g>
|
|
13
|
+
<defs>
|
|
14
|
+
<clipPath id="clip0">
|
|
15
|
+
<rect width="26" height="19" fill="white" transform="translate(3.5 7)" />
|
|
16
|
+
</clipPath>
|
|
17
|
+
</defs>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { Rspack } from "../src";
|
|
3
|
+
|
|
4
|
+
const context = path.resolve(__dirname, "../../../examples/react-with-sass");
|
|
5
|
+
|
|
6
|
+
const rspack = new Rspack({
|
|
7
|
+
entry: {
|
|
8
|
+
main: path.resolve(context, "./src/index.jsx")
|
|
9
|
+
},
|
|
10
|
+
context,
|
|
11
|
+
plugins: ["html"],
|
|
12
|
+
module: {
|
|
13
|
+
rules: [
|
|
14
|
+
{
|
|
15
|
+
test: "\\.s[ac]ss$",
|
|
16
|
+
uses: [{ builtinLoader: "sass-loader" }],
|
|
17
|
+
type: "css"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
const stats = await rspack.build();
|
|
25
|
+
console.log(stats);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/bin/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const commander_1 = require("commander");
|
|
4
|
+
const dev_server_1 = require("@rspack/dev-server");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const build_1 = require("../build");
|
|
7
|
+
const program = new commander_1.Command();
|
|
8
|
+
program
|
|
9
|
+
.option("--env", "env")
|
|
10
|
+
.command("build", {
|
|
11
|
+
isDefault: true
|
|
12
|
+
})
|
|
13
|
+
.description("Rspack build cli")
|
|
14
|
+
.argument("<config-file>", "rspack config file path")
|
|
15
|
+
.action(async (configPath) => {
|
|
16
|
+
const config = require(configPath);
|
|
17
|
+
const stats = await (0, build_1.build)(config);
|
|
18
|
+
console.log(stats);
|
|
19
|
+
});
|
|
20
|
+
program
|
|
21
|
+
.command("dev")
|
|
22
|
+
.description("Rspack build cli")
|
|
23
|
+
.argument("<config-file>", "rspack config file path")
|
|
24
|
+
.action(async (configPath) => {
|
|
25
|
+
const config = require(configPath);
|
|
26
|
+
const rspack = new __1.Rspack(config);
|
|
27
|
+
const { options: { dev: { port = 8080 } = {} } = {} } = rspack;
|
|
28
|
+
await rspack.build();
|
|
29
|
+
const server = await (0, dev_server_1.createServer)(rspack.options);
|
|
30
|
+
server.listen(port, () => console.log(`Server listening on port: ${port}`));
|
|
31
|
+
});
|
|
32
|
+
program.parse();
|
package/lib/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function build(config: any): Promise<void>;
|
package/lib/build.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
async function build(config) {
|
|
6
|
+
const rspack = new _1.Rspack(config);
|
|
7
|
+
const stats = await rspack.build();
|
|
8
|
+
if (stats.errors.length > 0) {
|
|
9
|
+
throw new Error(stats.errors[0].message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.build = build;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Dev {
|
|
2
|
+
port?: number;
|
|
3
|
+
static?: {
|
|
4
|
+
directory?: string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface ResolvedDev {
|
|
8
|
+
port: number;
|
|
9
|
+
static: {
|
|
10
|
+
directory: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface ResolveDevConfigContext {
|
|
14
|
+
context: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function resolveDevOptions(devConfig: Dev, context: ResolveDevConfigContext): ResolvedDev;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
exports.resolveDevOptions = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
function resolveDevOptions(devConfig = {}, context) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
return {
|
|
11
|
+
port: (_a = devConfig.port) !== null && _a !== void 0 ? _a : 8080,
|
|
12
|
+
static: {
|
|
13
|
+
directory: (_c = (_b = devConfig.static) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : node_path_1.default.resolve(context.context, "dist")
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.resolveDevOptions = resolveDevOptions;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Context, ResolvedContext } from "./context";
|
|
2
|
+
import type { Define, ResolvedDefine } from "./define";
|
|
3
|
+
import type { Dev, ResolvedDev } from "./dev";
|
|
4
|
+
import type { Entry, ResolvedEntry } from "./entry";
|
|
5
|
+
import type { External, ResolvedExternal } from "./external";
|
|
6
|
+
import type { Mode, ResolvedMode } from "./mode";
|
|
7
|
+
import type { Module, ResolvedModule } from "./module";
|
|
8
|
+
import type { Plugin } from "./plugin";
|
|
9
|
+
import type { ResolvedTarget, Target } from "./target";
|
|
10
|
+
import type { Output, ResolvedOutput } from "./output";
|
|
11
|
+
import { Builtins, ResolvedBuiltins } from "./builtins";
|
|
12
|
+
import { Resolve, ResolvedResolve } from "./resolve";
|
|
13
|
+
export declare type Asset = {
|
|
14
|
+
source: string;
|
|
15
|
+
};
|
|
16
|
+
export declare type Assets = Record<string, Asset>;
|
|
17
|
+
export interface RspackOptions {
|
|
18
|
+
entry?: Entry;
|
|
19
|
+
context?: Context;
|
|
20
|
+
plugins?: Plugin[];
|
|
21
|
+
dev?: Dev;
|
|
22
|
+
module?: Module;
|
|
23
|
+
define?: Define;
|
|
24
|
+
target?: Target;
|
|
25
|
+
mode?: Mode;
|
|
26
|
+
external?: External;
|
|
27
|
+
output?: Output;
|
|
28
|
+
builtins: Builtins;
|
|
29
|
+
resolve: Resolve;
|
|
30
|
+
}
|
|
31
|
+
export interface ResolvedRspackOptions {
|
|
32
|
+
entry: ResolvedEntry;
|
|
33
|
+
context: ResolvedContext;
|
|
34
|
+
plugins: Plugin[];
|
|
35
|
+
dev: ResolvedDev;
|
|
36
|
+
module: ResolvedModule;
|
|
37
|
+
define: ResolvedDefine;
|
|
38
|
+
target: ResolvedTarget;
|
|
39
|
+
mode: ResolvedMode;
|
|
40
|
+
external: ResolvedExternal;
|
|
41
|
+
output: ResolvedOutput;
|
|
42
|
+
builtins: ResolvedBuiltins;
|
|
43
|
+
resolve: ResolvedResolve;
|
|
44
|
+
}
|
|
45
|
+
export declare function resolveOptions(config: RspackOptions): ResolvedRspackOptions;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveOptions = void 0;
|
|
4
|
+
const target_1 = require("./target");
|
|
5
|
+
const output_1 = require("./output");
|
|
6
|
+
const dev_1 = require("./dev");
|
|
7
|
+
const module_1 = require("./module");
|
|
8
|
+
function resolveOptions(config) {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10
|
+
const context = (_a = config.context) !== null && _a !== void 0 ? _a : process.cwd();
|
|
11
|
+
const mode = (_b = config.mode) !== null && _b !== void 0 ? _b : "development";
|
|
12
|
+
const dev = (0, dev_1.resolveDevOptions)(config.dev, { context });
|
|
13
|
+
const entry = (_c = config.entry) !== null && _c !== void 0 ? _c : {};
|
|
14
|
+
const output = (0, output_1.resolveOutputOptions)(config.output);
|
|
15
|
+
const define = (_d = config.define) !== null && _d !== void 0 ? _d : {};
|
|
16
|
+
const target = (0, target_1.resolveTargetOptions)(config.target);
|
|
17
|
+
const external = (_e = config.external) !== null && _e !== void 0 ? _e : {};
|
|
18
|
+
const plugins = (_f = config.plugins) !== null && _f !== void 0 ? _f : [];
|
|
19
|
+
const builtins = (_g = config.builtins) !== null && _g !== void 0 ? _g : [];
|
|
20
|
+
const resolve = (_h = config.resolve) !== null && _h !== void 0 ? _h : {};
|
|
21
|
+
const module = (0, module_1.resolveModuleOptions)(config.module);
|
|
22
|
+
return {
|
|
23
|
+
context,
|
|
24
|
+
mode,
|
|
25
|
+
dev,
|
|
26
|
+
entry,
|
|
27
|
+
output,
|
|
28
|
+
define,
|
|
29
|
+
target,
|
|
30
|
+
external,
|
|
31
|
+
plugins,
|
|
32
|
+
builtins,
|
|
33
|
+
module,
|
|
34
|
+
resolve
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.resolveOptions = resolveOptions;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { RawModuleRuleUse, RawModuleRule } from "@rspack/binding";
|
|
3
|
+
export interface ModuleRule {
|
|
4
|
+
test?: RawModuleRule["test"];
|
|
5
|
+
resource?: RawModuleRule["resource"];
|
|
6
|
+
resourceQuery?: RawModuleRule["resourceQuery"];
|
|
7
|
+
uses?: ModuleRuleUse[];
|
|
8
|
+
type?: RawModuleRule["type"];
|
|
9
|
+
}
|
|
10
|
+
export interface Module {
|
|
11
|
+
rules?: ModuleRule[];
|
|
12
|
+
parser?: {
|
|
13
|
+
dataUrlCondition?: {
|
|
14
|
+
maxSize?: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface ResolvedModuleRule {
|
|
19
|
+
test?: RawModuleRule["test"];
|
|
20
|
+
resource?: RawModuleRule["resource"];
|
|
21
|
+
resourceQuery?: RawModuleRule["resourceQuery"];
|
|
22
|
+
uses?: RawModuleRuleUse[];
|
|
23
|
+
type?: RawModuleRule["type"];
|
|
24
|
+
}
|
|
25
|
+
export interface ResolvedModule {
|
|
26
|
+
rules: ResolvedModuleRule[];
|
|
27
|
+
parser?: {
|
|
28
|
+
dataUrlCondition: {
|
|
29
|
+
maxSize: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
interface LoaderContextInternal {
|
|
34
|
+
source: number[];
|
|
35
|
+
resource: String;
|
|
36
|
+
resourcePath: String;
|
|
37
|
+
resourceQuery: String | null;
|
|
38
|
+
resourceFragment: String | null;
|
|
39
|
+
}
|
|
40
|
+
interface LoaderResult {
|
|
41
|
+
content: Buffer | string;
|
|
42
|
+
meta: Buffer | string;
|
|
43
|
+
}
|
|
44
|
+
interface LoaderContext extends Pick<LoaderContextInternal, "resource" | "resourcePath" | "resourceQuery" | "resourceFragment"> {
|
|
45
|
+
source: {
|
|
46
|
+
getCode(): string;
|
|
47
|
+
getBuffer(): Buffer;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface JsLoader {
|
|
51
|
+
(this: LoaderContext, loaderContext: LoaderContext): Promise<LoaderResult | void> | LoaderResult | void;
|
|
52
|
+
displayName?: string;
|
|
53
|
+
}
|
|
54
|
+
declare type BuiltinLoader = string;
|
|
55
|
+
declare type ModuleRuleUse = {
|
|
56
|
+
builtinLoader: BuiltinLoader;
|
|
57
|
+
options?: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
loader: JsLoader;
|
|
60
|
+
options?: unknown;
|
|
61
|
+
};
|
|
62
|
+
export declare function createRawModuleRuleUses(uses: ModuleRuleUse[]): RawModuleRuleUse[];
|
|
63
|
+
export declare function resolveModuleOptions(module?: Module): ResolvedModule;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
exports.resolveModuleOptions = exports.createRawModuleRuleUses = void 0;
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const toBuffer = (bufLike) => {
|
|
9
|
+
if (Buffer.isBuffer(bufLike)) {
|
|
10
|
+
return bufLike;
|
|
11
|
+
}
|
|
12
|
+
else if (typeof bufLike === "string") {
|
|
13
|
+
return Buffer.from(bufLike);
|
|
14
|
+
}
|
|
15
|
+
throw new Error("Buffer or string expected");
|
|
16
|
+
};
|
|
17
|
+
function composeJsUse(uses) {
|
|
18
|
+
if (!uses.length) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
async function loader(err, data) {
|
|
22
|
+
if (err) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
const loaderThreadsafeContext = JSON.parse(data.toString("utf-8"));
|
|
26
|
+
const { p: payload, id } = loaderThreadsafeContext;
|
|
27
|
+
const loaderContextInternal = {
|
|
28
|
+
source: payload.source,
|
|
29
|
+
resourcePath: payload.resourcePath,
|
|
30
|
+
resourceQuery: payload.resourceQuery,
|
|
31
|
+
resource: payload.resource,
|
|
32
|
+
resourceFragment: payload.resourceFragment
|
|
33
|
+
};
|
|
34
|
+
let sourceBuffer = Buffer.from(loaderContextInternal.source);
|
|
35
|
+
let meta = Buffer.from("");
|
|
36
|
+
// Loader is executed from right to left
|
|
37
|
+
for (const use of uses) {
|
|
38
|
+
(0, node_assert_1.default)("loader" in use);
|
|
39
|
+
const loaderContext = {
|
|
40
|
+
...loaderContextInternal,
|
|
41
|
+
source: {
|
|
42
|
+
getCode() {
|
|
43
|
+
return sourceBuffer.toString("utf-8");
|
|
44
|
+
},
|
|
45
|
+
getBuffer() {
|
|
46
|
+
return sourceBuffer;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
getOptions() {
|
|
50
|
+
return use.options;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
let loaderResult;
|
|
54
|
+
if ((loaderResult = await Promise.resolve().then(() => use.loader.apply(loaderContext, [loaderContext])))) {
|
|
55
|
+
const content = loaderResult.content;
|
|
56
|
+
meta = meta.length > 0 ? meta : toBuffer(loaderResult.meta);
|
|
57
|
+
sourceBuffer = toBuffer(content);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const loaderResultPayload = {
|
|
61
|
+
content: [...sourceBuffer],
|
|
62
|
+
meta: [...meta]
|
|
63
|
+
};
|
|
64
|
+
const loaderThreadsafeResult = {
|
|
65
|
+
id: id,
|
|
66
|
+
p: loaderResultPayload
|
|
67
|
+
};
|
|
68
|
+
return Buffer.from(JSON.stringify(loaderThreadsafeResult), "utf-8");
|
|
69
|
+
}
|
|
70
|
+
loader.displayName = `NodeLoaderAdapter(${uses
|
|
71
|
+
.map(item => {
|
|
72
|
+
(0, node_assert_1.default)("loader" in item);
|
|
73
|
+
return item.loader.displayName || item.loader.name || "unknown-loader";
|
|
74
|
+
})
|
|
75
|
+
.join(" -> ")})`;
|
|
76
|
+
return {
|
|
77
|
+
loader
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function createRawModuleRuleUses(uses) {
|
|
81
|
+
return createRawModuleRuleUsesImpl([...uses].reverse());
|
|
82
|
+
}
|
|
83
|
+
exports.createRawModuleRuleUses = createRawModuleRuleUses;
|
|
84
|
+
function createRawModuleRuleUsesImpl(uses) {
|
|
85
|
+
if (!uses.length) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
const index = uses.findIndex(use => "builtinLoader" in use);
|
|
89
|
+
if (index < 0) {
|
|
90
|
+
return [composeJsUse(uses)];
|
|
91
|
+
}
|
|
92
|
+
const before = uses.slice(0, index);
|
|
93
|
+
const after = uses.slice(index + 1);
|
|
94
|
+
return [
|
|
95
|
+
composeJsUse(before),
|
|
96
|
+
createNativeUse(uses[index]),
|
|
97
|
+
...createRawModuleRuleUsesImpl(after)
|
|
98
|
+
].filter((item) => Boolean(item));
|
|
99
|
+
}
|
|
100
|
+
function createNativeUse(use) {
|
|
101
|
+
var _a;
|
|
102
|
+
(0, node_assert_1.default)("builtinLoader" in use);
|
|
103
|
+
if (use.builtinLoader === "sass-loader") {
|
|
104
|
+
((_a = use.options) !== null && _a !== void 0 ? _a : (use.options = {})).__exePath = require.resolve(`@tmp-sass-embedded/${process.platform}-${process.arch}/dart-sass-embedded/dart-sass-embedded${process.platform === "win32" ? ".bat" : ""}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
builtinLoader: use.builtinLoader,
|
|
108
|
+
options: JSON.stringify(use.options)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function resolveModuleOptions(module = {}) {
|
|
112
|
+
var _a;
|
|
113
|
+
const rules = ((_a = module.rules) !== null && _a !== void 0 ? _a : []).map(rule => ({
|
|
114
|
+
...rule,
|
|
115
|
+
uses: createRawModuleRuleUses(rule.uses || [])
|
|
116
|
+
}));
|
|
117
|
+
return {
|
|
118
|
+
rules
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.resolveModuleOptions = resolveModuleOptions;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Output {
|
|
2
|
+
path?: string;
|
|
3
|
+
publicPath?: string;
|
|
4
|
+
assetModuleFilename?: string;
|
|
5
|
+
filename?: string;
|
|
6
|
+
chunkFilename?: string;
|
|
7
|
+
uniqueName?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolvedOutput {
|
|
10
|
+
path?: string;
|
|
11
|
+
publicPath?: string;
|
|
12
|
+
assetModuleFilename?: string;
|
|
13
|
+
filename?: string;
|
|
14
|
+
chunkFilename?: string;
|
|
15
|
+
uniqueName?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function resolveOutputOptions(output?: Output): ResolvedOutput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveOutputOptions = void 0;
|
|
4
|
+
function resolveOutputOptions(output = {}) {
|
|
5
|
+
return {
|
|
6
|
+
path: output.path,
|
|
7
|
+
publicPath: output.publicPath,
|
|
8
|
+
chunkFilename: output.chunkFilename,
|
|
9
|
+
filename: output.publicPath,
|
|
10
|
+
assetModuleFilename: output.assetModuleFilename,
|
|
11
|
+
uniqueName: output.uniqueName
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.resolveOutputOptions = resolveOutputOptions;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare type TargetItem = "web" | "webworker" | "browserslist" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022";
|
|
2
|
+
export declare type Target = TargetItem | TargetItem[] | false;
|
|
3
|
+
export declare type ResolvedTarget = TargetItem[];
|
|
4
|
+
export declare function resolveTargetOptions(target?: Target): ResolvedTarget;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveTargetOptions = void 0;
|
|
4
|
+
function resolveTargetOptions(target = "web") {
|
|
5
|
+
if (!target) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
if (!Array.isArray(target)) {
|
|
9
|
+
return [target];
|
|
10
|
+
}
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
13
|
+
exports.resolveTargetOptions = resolveTargetOptions;
|