@nuxt/webpack-builder-nightly 5.0.0-29735165.f2e25d33 → 5.0.0-29735167.d597a4e3

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 (2) hide show
  1. package/dist/index.mjs +14 -105
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import pify from "pify";
3
+ import webpackDevMiddleware from "webpack-dev-middleware";
4
+ import webpackHotMiddleware from "webpack-hot-middleware";
3
5
  import { defu } from "defu";
4
6
  import { pathToFileURL } from "node:url";
5
7
  import { basename, isAbsolute, join, normalize, relative, resolve } from "pathe";
@@ -1292,9 +1294,6 @@ function clientNodeCompat(ctx) {
1292
1294
  }
1293
1295
  function clientHMR(ctx) {
1294
1296
  if (!ctx.isDev) return;
1295
- ctx.config.plugins ||= [];
1296
- ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
1297
- if (builder === "rspack") return;
1298
1297
  const clientOptions = ctx.userConfig.hotMiddleware?.client || {};
1299
1298
  const hotMiddlewareClientOptions = {
1300
1299
  reload: true,
@@ -1307,6 +1306,8 @@ function clientHMR(ctx) {
1307
1306
  };
1308
1307
  const hotMiddlewareClientOptionsStr = querystring.stringify(hotMiddlewareClientOptions);
1309
1308
  ctx.config.entry.app.unshift(`webpack-hot-middleware/client?${hotMiddlewareClientOptionsStr}`);
1309
+ ctx.config.plugins ||= [];
1310
+ ctx.config.plugins.push(new webpack.HotModuleReplacementPlugin());
1310
1311
  }
1311
1312
  function clientOptimization(ctx) {
1312
1313
  if (!ctx.nuxt.options.features.inlineStyles) return;
@@ -1489,6 +1490,7 @@ const bundle = async (nuxt) => {
1489
1490
  if (existingPlugin >= 0) plugins.splice(existingPlugin, 1);
1490
1491
  });
1491
1492
  await nuxt.callHook(`${builder}:config`, webpackConfigs);
1493
+ const mfs = nuxt.options.dev ? createMFS() : null;
1492
1494
  if (nuxt.options.ssr && !nuxt.options.dev) {
1493
1495
  const serverEntryFile = pathToFileURL(resolve(nuxt.options.buildDir, "dist/server/server.mjs")).href;
1494
1496
  setBuildOutput("serverEntry", () => `export { default } from ${JSON.stringify(serverEntryFile)}`);
@@ -1500,21 +1502,7 @@ const bundle = async (nuxt) => {
1500
1502
  if (ssrStylesPlugin) config.plugins.push(ssrStylesPlugin);
1501
1503
  }
1502
1504
  await nuxt.callHook(`${builder}:configResolved`, webpackConfigs);
1503
- if (builder === "rspack" && createRsbuild) {
1504
- const rsbuild = await createRsbuildInstance(webpackConfigs, nuxt);
1505
- if (nuxt.options.dev) {
1506
- await startRsbuildDevServer(rsbuild, nuxt);
1507
- return;
1508
- }
1509
- const compilers = await getRsbuildCompilers(rsbuild);
1510
- nuxt.hook("close", async () => {
1511
- for (const compiler of compilers) await new Promise((resolve) => compiler.close(resolve));
1512
- });
1513
- for (const c of compilers) await compile(c);
1514
- return;
1515
- }
1516
- const mfs = nuxt.options.dev ? createMFS() : null;
1517
- const compilers = webpackConfigs.map((config) => webpack(config));
1505
+ const compilers = builder === "rspack" && createRsbuild ? await createRsbuildCompilers(webpackConfigs, nuxt) : webpackConfigs.map((config) => webpack(config));
1518
1506
  if (nuxt.options.dev) for (const compiler of compilers) compiler.outputFileSystem = mfs;
1519
1507
  nuxt.hook("close", async () => {
1520
1508
  for (const compiler of compilers) await new Promise((resolve) => compiler.close(resolve));
@@ -1525,106 +1513,27 @@ const bundle = async (nuxt) => {
1525
1513
  }
1526
1514
  for (const c of compilers) await compile(c);
1527
1515
  };
1528
- function createRsbuildInstance(configs, nuxt) {
1516
+ async function createRsbuildCompilers(configs, nuxt) {
1529
1517
  const environments = {};
1530
- for (const config of configs) {
1531
- const isServer = config.name === "server";
1532
- if (nuxt.options.dev && !isServer) config.target ??= "web";
1533
- environments[config.name] = {
1534
- output: {
1535
- target: isServer ? "node" : "web",
1536
- distPath: { root: config.output.path }
1537
- },
1538
- tools: { rspack: () => config }
1539
- };
1540
- }
1541
- return createRsbuild({
1518
+ for (const config of configs) environments[config.name] = {
1519
+ output: { target: config.name === "server" ? "node" : "web" },
1520
+ tools: { rspack: () => config }
1521
+ };
1522
+ const compiler = await (await createRsbuild({
1542
1523
  callerName: "nuxt",
1543
1524
  cwd: nuxt.options.rootDir,
1544
1525
  config: {
1545
1526
  root: nuxt.options.rootDir,
1546
1527
  mode: nuxt.options.dev ? "development" : "production",
1547
1528
  logLevel: "silent",
1548
- environments,
1549
- ...nuxt.options.dev ? {
1550
- server: { middlewareMode: true },
1551
- dev: { client: { path: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir, "rsbuild-hmr") } }
1552
- } : {}
1529
+ environments
1553
1530
  }
1554
- });
1555
- }
1556
- async function getRsbuildCompilers(rsbuild) {
1557
- const compiler = await rsbuild.createCompiler();
1531
+ })).createCompiler();
1558
1532
  return "compilers" in compiler ? compiler.compilers : [compiler];
1559
1533
  }
1560
- async function startRsbuildDevServer(rsbuild, nuxt) {
1561
- const firstCompiles = [];
1562
- rsbuild.onAfterCreateCompiler(({ compiler }) => {
1563
- const compilers = "compilers" in compiler ? compiler.compilers : [compiler];
1564
- for (const c of compilers) {
1565
- const name = c.options.name;
1566
- nuxt.callHook(`${builder}:compile`, {
1567
- name,
1568
- compiler: c
1569
- });
1570
- let settled = false;
1571
- firstCompiles.push(new Promise((resolve, reject) => {
1572
- c.hooks.done.tap("load-resources", (stats) => {
1573
- nuxt.callHook(`${builder}:compiled`, {
1574
- name,
1575
- compiler: c,
1576
- stats
1577
- });
1578
- if (!settled) {
1579
- settled = true;
1580
- resolve();
1581
- }
1582
- });
1583
- c.hooks.failed.tap("nuxt-errorlog", (err) => {
1584
- if (!settled) {
1585
- settled = true;
1586
- reject(err);
1587
- }
1588
- });
1589
- }));
1590
- }
1591
- });
1592
- const devServer = await rsbuild.createDevServer();
1593
- nuxt.hook("close", () => devServer.close());
1594
- nuxt.hook("listen", (server) => {
1595
- devServer.connectWebSocket({ server });
1596
- devServer.afterListen();
1597
- });
1598
- await nuxt.callHook("server:devHandler", rsbuildToH3Handler(devServer.middlewares), { cors: () => true });
1599
- await Promise.all(firstCompiles);
1600
- }
1601
- function rsbuildToH3Handler(middlewares) {
1602
- return defineEventHandler(async (event) => {
1603
- const { req, res } = "runtime" in event ? event.runtime.node : event.node;
1604
- if (!isSameOriginRequest(req)) {
1605
- res.statusCode = 403;
1606
- res.end("Forbidden");
1607
- return;
1608
- }
1609
- await new Promise((resolve) => {
1610
- let settled = false;
1611
- const done = () => {
1612
- if (!settled) {
1613
- settled = true;
1614
- resolve();
1615
- }
1616
- };
1617
- res.on("finish", done);
1618
- res.on("close", done);
1619
- middlewares(req, res, () => done());
1620
- });
1621
- });
1622
- }
1623
1534
  async function createDevMiddleware(compiler) {
1624
1535
  const nuxt = useNuxt();
1625
1536
  logger.debug("Creating webpack middleware...");
1626
- const { default: webpackDevMiddleware } = await import("webpack-dev-middleware");
1627
- const { default: webpackHotMiddleware } = await import("webpack-hot-middleware");
1628
1537
  const devMiddleware = webpackDevMiddleware(compiler, {
1629
1538
  publicPath: joinURL(nuxt.options.app.baseURL, nuxt.options.app.buildAssetsDir),
1630
1539
  outputFileSystem: compiler.outputFileSystem,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/webpack-builder-nightly",
3
- "version": "5.0.0-29735165.f2e25d33",
3
+ "version": "5.0.0-29735167.d597a4e3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
29
- "@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-29735165.f2e25d33",
29
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-29735167.d597a4e3",
30
30
  "@vue/compiler-sfc": "3.5.39",
31
31
  "autoprefixer": "^10.5.2",
32
32
  "css-loader": "^7.1.4",
@@ -71,7 +71,7 @@
71
71
  "webpackbar": "^7.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29735165.f2e25d33",
74
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@5.0.0-29735167.d597a4e3",
75
75
  "@rspack/core": "2.1.3",
76
76
  "@types/webpack-bundle-analyzer": "4.7.0",
77
77
  "@types/webpack-hot-middleware": "2.25.12",
@@ -82,7 +82,7 @@
82
82
  "vue": "3.5.39"
83
83
  },
84
84
  "peerDependencies": {
85
- "nuxt": "npm:nuxt-nightly@5.0.0-29735165.f2e25d33",
85
+ "nuxt": "npm:nuxt-nightly@5.0.0-29735167.d597a4e3",
86
86
  "vue": "^3.3.4"
87
87
  },
88
88
  "engines": {