-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): load
@rspack/dev-server
on demand !breaking! will opt out…
… process.env.WEBPACK_SERVE on build mode
- Loading branch information
Showing
5 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
log(DEFINE_ME); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { readFile, run, runWatch } from "../../utils/test-utils"; | ||
import { resolve } from "path"; | ||
|
||
it("should not have `process.env.WEBPACK_SERVE` set on build mode", async () => { | ||
await run(__dirname, []); | ||
const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8"); | ||
|
||
expect(mainJs).toContain("WEBPACK_SERVE=<EMPTY>"); | ||
}); | ||
|
||
it("should have `process.env.WEBPACK_SERVE` set on serve mode", async () => { | ||
await runWatch(__dirname, ["serve"], { killString: /rspack compiled/i }); | ||
const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8"); | ||
|
||
expect(mainJs).toContain("WEBPACK_SERVE=true"); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/rspack-cli/tests/build/issue-6359/rspack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { WEBPACK_SERVE } = process.env; | ||
module.exports = /** @type {import('@rspack/cli').Configuration} */ { | ||
mode: "production", | ||
entry: "./entry.js", | ||
output: { clean: true }, | ||
plugins: [ | ||
{ | ||
apply(compiler) { | ||
new compiler.webpack.DefinePlugin({ | ||
DEFINE_ME: JSON.stringify( | ||
`WEBPACK_SERVE=${WEBPACK_SERVE ?? "<EMPTY>"}` | ||
) | ||
}).apply(compiler); | ||
} | ||
} | ||
], | ||
devServer: { | ||
devMiddleware: { | ||
writeToDisk: true | ||
} | ||
} | ||
}; |