Skip to content

Commit

Permalink
fix: cannot reading noEmitAssets (#2942)
Browse files Browse the repository at this point in the history
* fix: multiCompiler on dev server

* chore: changeset
  • Loading branch information
faga295 authored Apr 26, 2023
1 parent c684075 commit cafa227
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-badgers-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspack/dev-server": patch
---

fix cannot reading noEmitAssets by always getting the first compiler's noEmitAssets
9 changes: 3 additions & 6 deletions packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ export class RspackDevServer extends WebpackDevServer {
const webpackDevMiddlewareIndex = middlewares.findIndex(
mid => mid.name === "webpack-dev-middleware"
);
// @ts-expect-error
if (compiler.options.builtins.noEmitAssets) {
const compilers =
compiler instanceof MultiCompiler ? compiler.compilers : [compiler];
if (compilers[0].options.builtins.noEmitAssets) {
if (Array.isArray(this.options.static)) {
const compilers =
compiler instanceof MultiCompiler
? compiler.compilers
: [compiler];
const memoryAssetsMiddlewares = this.options.static.flatMap(
staticOptions => {
return staticOptions.publicPath.flatMap(publicPath => {
Expand Down
19 changes: 18 additions & 1 deletion packages/rspack-dev-server/tests/normalizeOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RspackOptions } from "@rspack/core";
import { RspackOptions, rspack } from "@rspack/core";
import { RspackDevServer, Configuration } from "@rspack/dev-server";
import { createCompiler } from "@rspack/core";
import serializer from "jest-serializer-path";
Expand All @@ -9,6 +9,7 @@ expect.addSnapshotSerializer(serializer);
// default is to avoid stack overflow trigged
// by `webpack/schemas/WebpackOption.check.js` in debug mode
const ENTRY = "./placeholder.js";
const ENTRY1 = "./placeholder1.js";

describe("normalize options snapshot", () => {
it("no options", async () => {
Expand Down Expand Up @@ -74,6 +75,22 @@ describe("normalize options snapshot", () => {
expect(server.options.hot).toBe(true);
await server.stop();
});

it("should support multi-compiler", async () => {
const compiler = rspack([
{
entry: ENTRY,
stats: "none"
},
{
entry: ENTRY1,
stats: "none"
}
]);
const server = new RspackDevServer({}, compiler);
await server.start();
await server.stop();
});
});

async function match(config: RspackOptions) {
Expand Down
Empty file.

0 comments on commit cafa227

Please sign in to comment.