@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +1 -0
  3. package/bin.js +1 -0
  4. package/dist/bin/index.d.ts +1 -0
  5. package/dist/bin/index.js +32 -0
  6. package/dist/build.d.ts +1 -0
  7. package/dist/build.js +12 -0
  8. package/dist/config.d.ts +51 -0
  9. package/dist/config.js +26 -0
  10. package/dist/index.d.ts +73 -0
  11. package/dist/index.js +229 -0
  12. package/dist/server/index.d.ts +0 -0
  13. package/dist/server/index.js +0 -0
  14. package/example/basic.ts +71 -0
  15. package/example/react-example/index.html +12 -0
  16. package/example/react-example/package.json +17 -0
  17. package/example/react-example/rspack.config.json +13 -0
  18. package/example/react-example/src/app.jsx +44 -0
  19. package/example/react-example/src/base.css +9 -0
  20. package/example/react-example/src/button.jsx +3 -0
  21. package/example/react-example/src/dark.svg +1 -0
  22. package/example/react-example/src/data.json +5 -0
  23. package/example/react-example/src/file.jpg +0 -0
  24. package/example/react-example/src/file.png +0 -0
  25. package/example/react-example/src/file.svg +1 -0
  26. package/example/react-example/src/foo.css +3 -0
  27. package/example/react-example/src/index.html +32 -0
  28. package/example/react-example/src/index.js +1 -0
  29. package/example/react-example/src/light.svg +48 -0
  30. package/example/react-example/src/logo.svg +18 -0
  31. package/example/react-with-sass.ts +28 -0
  32. package/lib/bin/index.d.ts +1 -0
  33. package/lib/bin/index.js +32 -0
  34. package/lib/build.d.ts +1 -0
  35. package/lib/build.js +12 -0
  36. package/lib/config/builtins.d.ts +3 -0
  37. package/lib/config/builtins.js +2 -0
  38. package/lib/config/context.d.ts +2 -0
  39. package/lib/config/context.js +2 -0
  40. package/lib/config/define.d.ts +2 -0
  41. package/lib/config/define.js +2 -0
  42. package/lib/config/dev.d.ts +17 -0
  43. package/lib/config/dev.js +17 -0
  44. package/lib/config/entry.d.ts +2 -0
  45. package/lib/config/entry.js +2 -0
  46. package/lib/config/external.d.ts +2 -0
  47. package/lib/config/external.js +2 -0
  48. package/lib/config/index.d.ts +45 -0
  49. package/lib/config/index.js +37 -0
  50. package/lib/config/mode.d.ts +2 -0
  51. package/lib/config/mode.js +2 -0
  52. package/lib/config/module.d.ts +64 -0
  53. package/lib/config/module.js +121 -0
  54. package/lib/config/output.d.ts +17 -0
  55. package/lib/config/output.js +14 -0
  56. package/lib/config/plugin.d.ts +5 -0
  57. package/lib/config/plugin.js +2 -0
  58. package/lib/config/resolve.d.ts +6 -0
  59. package/lib/config/resolve.js +2 -0
  60. package/lib/config/target.d.ts +5 -0
  61. package/lib/config/target.js +13 -0
  62. package/lib/index.d.ts +39 -0
  63. package/lib/index.js +154 -0
  64. package/lib/server/index.d.ts +0 -0
  65. package/lib/server/index.js +0 -0
  66. package/package.json +49 -0
  67. package/src/bin/index.ts +36 -0
  68. package/src/build.ts +8 -0
  69. package/src/config/builtins.ts +5 -0
  70. package/src/config/context.ts +3 -0
  71. package/src/config/define.ts +3 -0
  72. package/src/config/dev.ts +32 -0
  73. package/src/config/entry.ts +3 -0
  74. package/src/config/external.ts +3 -0
  75. package/src/config/index.ts +80 -0
  76. package/src/config/mode.ts +2 -0
  77. package/src/config/module.ts +240 -0
  78. package/src/config/output.ts +29 -0
  79. package/src/config/plugin.ts +6 -0
  80. package/src/config/resolve.ts +6 -0
  81. package/src/config/target.ts +29 -0
  82. package/src/index.ts +140 -0
  83. package/src/server/index.ts +0 -0
  84. package/tests/config.test.ts +40 -0
  85. package/tsconfig.json +14 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,51 @@
1
+ # @rspack/core
2
+
3
+ ## 0.0.0-20220909025136
4
+
5
+ ### Patch Changes
6
+
7
+ - 53ee00d1: test alpha publish
8
+ - Updated dependencies [53ee00d1]
9
+ - @rspack/binding@0.0.0-20220909025136
10
+ - @rspack/dev-server@0.0.0-20220909025136
11
+ - @rspack/plugin-postcss@0.0.0-20220909025136
12
+
13
+ ## 0.0.6
14
+
15
+ ### Patch Changes
16
+
17
+ - e6d0926a: unify version
18
+ - Updated dependencies [e6d0926a]
19
+ - @rspack/binding@0.0.6
20
+ - @rspack/dev-server@0.0.6
21
+ - @rspack/plugin-postcss@0.0.6
22
+
23
+ ## 0.0.4
24
+
25
+ ### Patch Changes
26
+
27
+ - d466288: add process_assets hook
28
+ - Updated dependencies [d466288]
29
+ - @rspack/binding@0.0.5
30
+ - @rspack/dev-server@0.0.4
31
+ - @rspack/plugin-postcss@0.0.4
32
+
33
+ ## 0.0.3
34
+
35
+ ### Patch Changes
36
+
37
+ - 536f6f70: fix broken lib
38
+ - Updated dependencies [536f6f70]
39
+ - @rspack/binding@0.0.4
40
+ - @rspack/dev-server@0.0.3
41
+ - @rspack/plugin-postcss@0.0.3
42
+
43
+ ## 0.0.2
44
+
45
+ ### Patch Changes
46
+
47
+ - bd57e818: first release
48
+ - Updated dependencies [bd57e818]
49
+ - @rspack/binding@0.0.2
50
+ - rspack-dev-server@0.0.2
51
+ - rspack-plugin-postcss@0.0.2
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # rspack
package/bin.js ADDED
@@ -0,0 +1 @@
1
+ require("./dist/bin/index");
@@ -0,0 +1 @@
1
+ export {};
@@ -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();
@@ -0,0 +1 @@
1
+ export declare function build(config: any): Promise<void>;
package/dist/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,51 @@
1
+ /// <reference types="node" />
2
+ import type { RawOptions } from "@rspack/binding";
3
+ import type { ModuleRule } from ".";
4
+ import Rspack from ".";
5
+ export declare type Asset = {
6
+ source?: string;
7
+ buffer?: Buffer;
8
+ };
9
+ export declare type Assets = Record<string, Asset>;
10
+ export declare type Plugin = {
11
+ name: string;
12
+ apply(compiler: Rspack): void;
13
+ };
14
+ export interface RspackOptions {
15
+ /**
16
+ * Entry points of compilation.
17
+ */
18
+ entry?: RawOptions["entry"];
19
+ /**
20
+ * An **absolute** path pointed the
21
+ */
22
+ context?: RawOptions["context"];
23
+ /**
24
+ * An array of plugins
25
+ */
26
+ plugins?: Plugin[];
27
+ /**
28
+ * dev server
29
+ */
30
+ dev?: {
31
+ port?: Number;
32
+ static?: {
33
+ directory?: string;
34
+ };
35
+ };
36
+ /**
37
+ * Module configuration.
38
+ */
39
+ module?: {
40
+ rules?: ModuleRule[];
41
+ parser?: RawOptions["module"]["parser"];
42
+ };
43
+ define?: RawOptions["define"];
44
+ target?: RawOptions["target"];
45
+ mode?: RawOptions["mode"];
46
+ external?: RawOptions["external"];
47
+ output?: RawOptions["output"];
48
+ }
49
+ export declare function User2Native(config: RspackOptions): RawOptions & {
50
+ plugins: Plugin[];
51
+ };
package/dist/config.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.User2Native = void 0;
4
+ const _1 = require(".");
5
+ function User2Native(config) {
6
+ var _a, _b, _c, _d;
7
+ return {
8
+ entry: (_a = config.entry) !== null && _a !== void 0 ? _a : {},
9
+ context: config.context,
10
+ output: config.output,
11
+ define: config.define,
12
+ target: config.target,
13
+ external: config.external,
14
+ plugins: (_b = config.plugins) !== null && _b !== void 0 ? _b : [],
15
+ module: {
16
+ // TODO: support mutliple rules to support `Module Type`
17
+ rules: ((_d = (_c = config === null || config === void 0 ? void 0 : config.module) === null || _c === void 0 ? void 0 : _c.rules) !== null && _d !== void 0 ? _d : []).map(rule => {
18
+ return {
19
+ ...rule,
20
+ uses: (0, _1.createRawModuleRuleUses)(rule.uses || [])
21
+ };
22
+ })
23
+ }
24
+ };
25
+ }
26
+ exports.User2Native = User2Native;
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+ export * from "./build";
3
+ import * as binding from "@rspack/binding";
4
+ import type { RawModuleRuleUse, RawModuleRule } from "@rspack/binding";
5
+ import * as tapable from "tapable";
6
+ import * as Config from "./config";
7
+ import type { RspackOptions } from "./config";
8
+ interface ModuleRule {
9
+ test?: RawModuleRule["test"];
10
+ resource?: RawModuleRule["resource"];
11
+ resourceQuery?: RawModuleRule["resourceQuery"];
12
+ uses?: ModuleRuleUse[];
13
+ type?: RawModuleRule["type"];
14
+ }
15
+ declare type ModuleRuleUse = {
16
+ builtinLoader: BuiltinLoader;
17
+ options?: unknown;
18
+ } | {
19
+ loader: JsLoader;
20
+ options?: unknown;
21
+ };
22
+ interface JsLoader {
23
+ (this: LoaderContext, loaderContext: LoaderContext): Promise<LoaderResult | void> | LoaderResult | void;
24
+ displayName?: string;
25
+ }
26
+ declare type BuiltinLoader = string;
27
+ interface LoaderContextInternal {
28
+ source: number[];
29
+ resource: String;
30
+ resourcePath: String;
31
+ resourceQuery: String | null;
32
+ resourceFragment: String | null;
33
+ }
34
+ interface LoaderContext extends Pick<LoaderContextInternal, "resource" | "resourcePath" | "resourceQuery" | "resourceFragment"> {
35
+ source: {
36
+ getCode(): string;
37
+ getBuffer(): Buffer;
38
+ };
39
+ }
40
+ interface LoaderResult {
41
+ content: Buffer | string;
42
+ meta: Buffer | string;
43
+ }
44
+ declare function createRawModuleRuleUses(uses: ModuleRuleUse[]): RawModuleRuleUse[];
45
+ declare type EmitAssetCallback = (options: {
46
+ filename: string;
47
+ asset: Config.Asset;
48
+ }) => void;
49
+ declare class RspackCompilation {
50
+ emitAssetCallback: EmitAssetCallback;
51
+ hooks: {
52
+ processAssets: tapable.AsyncSeriesHook<Config.Assets>;
53
+ };
54
+ constructor();
55
+ updateAsset(filename: string, asset: Config.Asset): void;
56
+ emitAsset(finame: string, asset: Config.Asset): void;
57
+ procssAssets(err: Error, value: string, emitAsset: any): Promise<string>;
58
+ }
59
+ declare class Rspack {
60
+ #private;
61
+ options: RspackOptions;
62
+ compilation: RspackCompilation;
63
+ hooks: {
64
+ done: tapable.AsyncSeriesHook<void>;
65
+ compilation: tapable.SyncHook<RspackCompilation>;
66
+ };
67
+ constructor(options: RspackOptions);
68
+ build(): Promise<binding.Stats>;
69
+ rebuild(): Promise<Record<string, string>>;
70
+ }
71
+ export { Rspack, createRawModuleRuleUses };
72
+ export type { ModuleRule };
73
+ export default Rspack;
package/dist/index.js ADDED
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
29
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
30
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
31
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
32
+ };
33
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
34
+ if (kind === "m") throw new TypeError("Private method is not writable");
35
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
36
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
37
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
38
+ };
39
+ var __importDefault = (this && this.__importDefault) || function (mod) {
40
+ return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ };
42
+ var _Rspack_instances, _Rspack_plugins, _Rspack_instance, _Rspack_done, _Rspack_procssAssets, _Rspack_newCompilation;
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.createRawModuleRuleUses = exports.Rspack = void 0;
45
+ __exportStar(require("./build"), exports);
46
+ const binding = __importStar(require("@rspack/binding"));
47
+ const tapable = __importStar(require("tapable"));
48
+ const node_assert_1 = __importDefault(require("node:assert"));
49
+ const Config = __importStar(require("./config"));
50
+ const toBuffer = (bufLike) => {
51
+ if (Buffer.isBuffer(bufLike)) {
52
+ return bufLike;
53
+ }
54
+ else if (typeof bufLike === "string") {
55
+ return Buffer.from(bufLike);
56
+ }
57
+ throw new Error("Buffer or string expected");
58
+ };
59
+ function createRawModuleRuleUses(uses) {
60
+ return createRawModuleRuleUsesImpl([...uses].reverse());
61
+ }
62
+ exports.createRawModuleRuleUses = createRawModuleRuleUses;
63
+ function createRawModuleRuleUsesImpl(uses) {
64
+ const index = uses.findIndex(use => "builtinLoader" in use);
65
+ if (index < 0) {
66
+ return [composeJsUse(uses)];
67
+ }
68
+ const before = uses.slice(0, index);
69
+ const after = uses.slice(index + 1);
70
+ return [
71
+ composeJsUse(before),
72
+ createNativeUse(uses[index]),
73
+ ...createRawModuleRuleUsesImpl(after)
74
+ ];
75
+ }
76
+ function createNativeUse(use) {
77
+ var _a;
78
+ (0, node_assert_1.default)("builtinLoader" in use);
79
+ if (use.builtinLoader === "sass-loader") {
80
+ ((_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" : ""}`);
81
+ }
82
+ return {
83
+ builtinLoader: use.builtinLoader,
84
+ options: JSON.stringify(use.options)
85
+ };
86
+ }
87
+ function composeJsUse(uses) {
88
+ async function loader(err, data) {
89
+ if (err) {
90
+ throw err;
91
+ }
92
+ const loaderThreadsafeContext = JSON.parse(data.toString("utf-8"));
93
+ const { p: payload, id } = loaderThreadsafeContext;
94
+ const loaderContextInternal = {
95
+ source: payload.source,
96
+ resourcePath: payload.resourcePath,
97
+ resourceQuery: payload.resourceQuery,
98
+ resource: payload.resource,
99
+ resourceFragment: payload.resourceFragment
100
+ };
101
+ let sourceBuffer = Buffer.from(loaderContextInternal.source);
102
+ let meta = Buffer.from("");
103
+ // Loader is executed from right to left
104
+ for (const use of uses) {
105
+ (0, node_assert_1.default)("loader" in use);
106
+ const loaderContext = {
107
+ ...loaderContextInternal,
108
+ source: {
109
+ getCode() {
110
+ return sourceBuffer.toString("utf-8");
111
+ },
112
+ getBuffer() {
113
+ return sourceBuffer;
114
+ }
115
+ },
116
+ getOptions() {
117
+ return use.options;
118
+ }
119
+ };
120
+ let loaderResult;
121
+ if ((loaderResult = await Promise.resolve().then(() => use.loader.apply(loaderContext, [loaderContext])))) {
122
+ const content = loaderResult.content;
123
+ meta = meta.length > 0 ? meta : toBuffer(loaderResult.meta);
124
+ sourceBuffer = toBuffer(content);
125
+ }
126
+ }
127
+ const loaderResultPayload = {
128
+ content: [...sourceBuffer],
129
+ meta: [...meta]
130
+ };
131
+ const loaderThreadsafeResult = {
132
+ id: id,
133
+ p: loaderResultPayload
134
+ };
135
+ return Buffer.from(JSON.stringify(loaderThreadsafeResult), "utf-8");
136
+ }
137
+ loader.displayName = `NodeLoaderAdapter(${uses
138
+ .map(item => {
139
+ (0, node_assert_1.default)("loader" in item);
140
+ return item.loader.displayName || item.loader.name || "unknown-loader";
141
+ })
142
+ .join(" -> ")})`;
143
+ return {
144
+ loader
145
+ };
146
+ }
147
+ const createDummyResult = (id) => {
148
+ const result = {
149
+ id,
150
+ inner: null
151
+ };
152
+ return JSON.stringify(result);
153
+ };
154
+ class RspackCompilation {
155
+ constructor() {
156
+ this.hooks = {
157
+ processAssets: new tapable.AsyncSeriesHook(["assets"])
158
+ };
159
+ }
160
+ updateAsset(filename, asset) {
161
+ this.emitAsset(filename, asset);
162
+ }
163
+ emitAsset(finame, asset) {
164
+ if (!this.emitAssetCallback) {
165
+ throw new Error("can't call emitAsset outof processAssets hook for now");
166
+ }
167
+ this.emitAssetCallback({
168
+ filename: finame,
169
+ asset
170
+ });
171
+ }
172
+ async procssAssets(err, value, emitAsset) {
173
+ this.emitAssetCallback = emitAsset;
174
+ if (err) {
175
+ throw err;
176
+ }
177
+ const context = JSON.parse(value);
178
+ await this.hooks.processAssets.promise(context === null || context === void 0 ? void 0 : context.inner);
179
+ return createDummyResult(context.id);
180
+ }
181
+ }
182
+ class Rspack {
183
+ constructor(options) {
184
+ var _a;
185
+ this.options = options;
186
+ _Rspack_instances.add(this);
187
+ _Rspack_plugins.set(this, void 0);
188
+ _Rspack_instance.set(this, void 0);
189
+ const nativeConfig = Config.User2Native(options);
190
+ __classPrivateFieldSet(this, _Rspack_instance, binding.newRspack(nativeConfig, {
191
+ doneCallback: __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_done).bind(this),
192
+ processAssetsCallback: __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_procssAssets).bind(this)
193
+ }), "f");
194
+ this.hooks = {
195
+ done: new tapable.AsyncSeriesHook(),
196
+ compilation: new tapable.SyncHook(["compilation"])
197
+ };
198
+ __classPrivateFieldSet(this, _Rspack_plugins, (_a = options.plugins) !== null && _a !== void 0 ? _a : [], "f");
199
+ for (const plugin of __classPrivateFieldGet(this, _Rspack_plugins, "f")) {
200
+ plugin.apply(this);
201
+ }
202
+ }
203
+ async build() {
204
+ const compilation = __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_newCompilation).call(this);
205
+ const stats = await binding.build(__classPrivateFieldGet(this, _Rspack_instance, "f"));
206
+ return stats;
207
+ }
208
+ async rebuild() {
209
+ const stats = await binding.rebuild(__classPrivateFieldGet(this, _Rspack_instance, "f"));
210
+ return stats;
211
+ }
212
+ }
213
+ exports.Rspack = Rspack;
214
+ _Rspack_plugins = new WeakMap(), _Rspack_instance = new WeakMap(), _Rspack_instances = new WeakSet(), _Rspack_done = async function _Rspack_done(err, value) {
215
+ if (err) {
216
+ throw err;
217
+ }
218
+ const context = JSON.parse(value);
219
+ await this.hooks.done.promise();
220
+ return createDummyResult(context.id);
221
+ }, _Rspack_procssAssets = async function _Rspack_procssAssets(err, value, emitAsset) {
222
+ return this.compilation.procssAssets(err, value, emitAsset);
223
+ }, _Rspack_newCompilation = function _Rspack_newCompilation() {
224
+ const compilation = new RspackCompilation();
225
+ this.compilation = compilation;
226
+ this.hooks.compilation.call(compilation);
227
+ return compilation;
228
+ };
229
+ exports.default = Rspack;
File without changes
File without changes
@@ -0,0 +1,71 @@
1
+ import path from "path";
2
+ import postcssLoader from "@rspack/plugin-postcss";
3
+ import { Rspack } from "../src";
4
+
5
+ const rspack = new Rspack({
6
+ entry: {
7
+ main: path.resolve(__dirname, "../../../examples/postcss/index.js")
8
+ },
9
+ context: path.resolve(__dirname, "../../../examples/postcss"),
10
+ plugins: [
11
+ {
12
+ name: "test",
13
+ apply(compiler) {
14
+ compiler.hooks.done.tap("done1", () => {
15
+ console.log("done1");
16
+ });
17
+ compiler.hooks.done.tap("done2", () => {
18
+ console.log("done2");
19
+ });
20
+ compiler.hooks.compilation.tap("compilation", compilation => {
21
+ compilation.hooks.processAssets.tapPromise(
22
+ "processAssets1",
23
+ async assets => {
24
+ for (const value of Object.values(assets)) {
25
+ console.log("value:", value.buffer(), value.source());
26
+ }
27
+ compilation.emitAsset("test.js", {
28
+ source: "hello world"
29
+ });
30
+ compilation.updateAsset("main.js", {
31
+ source: "hello main"
32
+ });
33
+ }
34
+ );
35
+ });
36
+ }
37
+ }
38
+ ],
39
+ module: {
40
+ rules: [
41
+ {
42
+ test: ".module.css$",
43
+ uses: [
44
+ {
45
+ loader: postcssLoader,
46
+ options: {
47
+ modules: true
48
+ }
49
+ }
50
+ // {
51
+ // loader: function testLoader(loaderContext) {
52
+ // // console.log(loaderContext);
53
+ // return {
54
+ // content: loaderContext.source.getBufFer(),
55
+ // meta: Buffer.from("something")
56
+ // };
57
+ // }
58
+ // }
59
+ ]
60
+ }
61
+ ]
62
+ }
63
+ });
64
+
65
+ async function main() {
66
+ const stats = await rspack.build();
67
+ console.log(stats);
68
+ // assert(stats.assets.length > 0)
69
+ }
70
+
71
+ main();
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Document</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "react-example",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "dev": "rspack dev rspack.config.json"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@rspack/core": "workspace:*",
14
+ "react": "17.0.0",
15
+ "react-dom": "17.0.0"
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "mode": "development",
3
+ "entry": {
4
+ "main": "./src/index.js"
5
+ },
6
+ "dev": {
7
+ "port": 8081,
8
+ "static": {
9
+ "directory": "dist"
10
+ }
11
+ },
12
+ "plugins": ["html"]
13
+ }
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import './base.css';
4
+ import LogoJPG from './file.jpg';
5
+ import LogoPNG from './file.png';
6
+ import LogoSVG from './file.svg';
7
+ import Json from './data.json';
8
+ // import Dark from './dark.svg';
9
+ // import Light from './light.svg'
10
+ // import LogoUrl from './logo.svg'
11
+ // import Logo from './logo.svg'
12
+ // const Button = React.lazy(() => import('../src/button'))
13
+
14
+ // console.log('LogoUrl', LogoUrl)
15
+ // console.log('Logo', Logo)
16
+
17
+ const App = () => {
18
+ return (
19
+ <React.Suspense fallback={<div>loading...</div>}>
20
+ <div>hello world</div>
21
+ {/* <Button></Button> */}
22
+
23
+ <img
24
+ style={{ width: '40px', height: '40px' }}
25
+ src={LogoJPG}
26
+ alt="logo jpg"
27
+ />
28
+ <img
29
+ style={{ width: '40px', height: '40px' }}
30
+ src={LogoPNG}
31
+ alt="logo png"
32
+ />
33
+ <img
34
+ style={{ width: '40px', height: '40px' }}
35
+ src={LogoSVG}
36
+ alt="logo svg"
37
+ />
38
+ {/* <Logo width={'40px'} height={'40px'} />
39
+ <Light width={'40px'} height={'40px'} />
40
+ <Dark width={'40px'} height={'40px'} /> */}
41
+ </React.Suspense>
42
+ );
43
+ };
44
+ ReactDOM.render(<App />, document.getElementById('root'));
@@ -0,0 +1,9 @@
1
+ @import './foo.css';
2
+
3
+ body {
4
+ background: gray;
5
+ background-image: url('./logo.svg');
6
+ }
7
+ .class {
8
+ box-shadow: 10px 5px 5px red;
9
+ }
@@ -0,0 +1,3 @@
1
+ import React from 'react'
2
+ const button = () => <div>cute button</div>
3
+ export default button
@@ -0,0 +1 @@
1
+ <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1599669065723" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="18411" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M390 250c0-52.6 10.6-102.6 29.8-148.2C237.4 146 102 310.2 102 506c0 229.6 186.4 416 416 416 195.8 0 360-135.4 404.2-317.8-45.6 19.2-95.8 29.8-148.2 29.8-212 0-384-172-384-384z" p-id="18412"></path></svg>