From 9abf7502a7e82130af80d58371cb45776af88866 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Thu, 4 Jan 2024 12:05:51 +0800 Subject: [PATCH] fix --- .../cases/react/tailwindcss/rspack.config.js | 1 + packages/playground/fixtures/rspack.ts | 46 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/playground/cases/react/tailwindcss/rspack.config.js b/packages/playground/cases/react/tailwindcss/rspack.config.js index 89d3b638496c..413c1b2d9e4c 100644 --- a/packages/playground/cases/react/tailwindcss/rspack.config.js +++ b/packages/playground/cases/react/tailwindcss/rspack.config.js @@ -4,6 +4,7 @@ const ReactRefreshPlugin = require("@rspack/plugin-react-refresh"); module.exports = { context: __dirname, + mode: "development", entry: { main: "./src/main.jsx" }, diff --git a/packages/playground/fixtures/rspack.ts b/packages/playground/fixtures/rspack.ts index 85232729620b..8d6872430d89 100644 --- a/packages/playground/fixtures/rspack.ts +++ b/packages/playground/fixtures/rspack.ts @@ -6,7 +6,7 @@ import WebpackDevServer from "webpack-dev-server"; import type { PathInfoFixtures } from "./pathInfo"; import { sleep } from "@/utils/sleep"; -class Rspack { +class RspackTestFixture { projectDir: string; compiler: Compiler; devServer: RspackDevServer | WebpackDevServer; @@ -75,7 +75,7 @@ export type RspackOptions = { }; export type RspackFixtures = { - rspack: Rspack; + rspack: RspackTestFixture; }; type RspackWorkerFixtures = { @@ -83,7 +83,7 @@ type RspackWorkerFixtures = { testFile: string, tempProjectDir: string, handleRspackConfig: (config: Configuration) => Configuration - ) => Promise; + ) => Promise; }; export const rspackFixtures = ( @@ -100,15 +100,15 @@ export const rspackFixtures = ( { page, pathInfo, _startRspackServer, defaultRspackConfig }, use ) => { - const rspack = await _startRspackServer( + const rspackTest = await _startRspackServer( pathInfo.testFile, pathInfo.tempProjectDir, defaultRspackConfig.handleConfig ); - const port = rspack.devServer.options.port; - await rspack.waitingForBuild(); + const port = rspackTest.devServer.options.port; + await rspackTest.waitingForBuild(); await page.goto(`http://localhost:${port}`); - await use(rspack); + await use(rspackTest); }, { auto: true @@ -118,16 +118,18 @@ export const rspackFixtures = ( _startRspackServer: [ async ({}, use, { workerIndex }) => { let currentTestFile = ""; - let rspack: Rspack | null = null as any; + let rspackTest: RspackTestFixture | null = null as any; await use(async function (testFile, projectDir, handleRspackConfig) { - if (rspack && currentTestFile !== testFile) { - await rspack.devServer.stop(); - rspack = null; + if (rspackTest && currentTestFile !== testFile) { + await rspackTest.devServer.stop(); + rspackTest = null; currentTestFile = testFile; } - if (!rspack) { + if (!rspackTest) { const port = 8000 + workerIndex; - rspack = new Rspack(projectDir, wds, function (config) { + rspackTest = new RspackTestFixture(projectDir, wds, function ( + config + ) { // rewrite port if (!config.devServer) { config.devServer = {}; @@ -140,28 +142,24 @@ export const rspackFixtures = ( } // set default define - if (!config.builtins) { - config.builtins = {}; - } - config.builtins.define = Object.assign( - { + (config.plugins ??= []).push( + new rspack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify( config.mode || "development" ) - }, - config.builtins.define + }) ); return handleRspackConfig(config); }); - await rspack.devServer.start(); + await rspackTest.devServer.start(); } - return rspack; + return rspackTest; }); - if (rspack?.projectDir) { - await rspack.devServer.stop(); + if (rspackTest?.projectDir) { + await rspackTest.devServer.stop(); } }, {