@bonsae/nrg 0.28.0 → 0.28.1

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/package.json +1 -1
  2. package/vite/index.js +21 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonsae/nrg",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "NRG framework — build Node-RED nodes with Vue 3, TypeScript, and JSON Schema",
5
5
  "author": "Allan Oricil <allanoricil@duck.com>",
6
6
  "license": "MIT",
package/vite/index.js CHANGED
@@ -3,6 +3,7 @@ import path15 from "path";
3
3
 
4
4
  // src/vite/defaults.ts
5
5
  var DEFAULT_OUTPUT_DIR = "./dist";
6
+ var DEFAULT_DEV_OUTPUT_DIR = "./.nrg";
6
7
  var DEFAULT_RESOURCES_DIR = "./src/resources";
7
8
  var DEFAULT_CLIENT_BUILD_OPTIONS = {
8
9
  srcDir: "./src/client",
@@ -3387,6 +3388,9 @@ function buildPlugin(options) {
3387
3388
  }
3388
3389
 
3389
3390
  // src/vite/plugin.ts
3391
+ function resolveIsDev(env) {
3392
+ return env.command === "serve";
3393
+ }
3390
3394
  function nrg(options = {}) {
3391
3395
  const { build: build3 = {}, server = {} } = options;
3392
3396
  const { outDir = DEFAULT_OUTPUT_DIR } = build3;
@@ -3408,18 +3412,33 @@ function nrg(options = {}) {
3408
3412
  ...discoverResourceCopyTargets(resourcesDir)
3409
3413
  ];
3410
3414
  const resolvedOutDir = path15.resolve(outDir);
3415
+ const resolvedDevOutDir = path15.resolve(DEFAULT_DEV_OUTPUT_DIR);
3411
3416
  const buildContext = {
3417
+ // outDir + isDev are authoritative once the `config` hook runs (from vite's
3418
+ // command, see resolveIsDev). These defaults only matter if a build hook
3419
+ // somehow ran before `config`, which vite never does.
3412
3420
  outDir: resolvedOutDir,
3413
3421
  packageName: getPackageName(),
3414
- isDev: process.env.NODE_ENV === "development",
3422
+ isDev: false,
3415
3423
  serverSrcDir: path15.resolve(serverBuildOptions.srcDir ?? "./server"),
3416
3424
  resourcesDir
3417
3425
  };
3418
3426
  const nodeRedLauncher = new NodeRedLauncher(
3419
- resolvedOutDir,
3427
+ resolvedDevOutDir,
3420
3428
  nodeRedLauncherOptions
3421
3429
  );
3422
3430
  return [
3431
+ {
3432
+ // Resolve dev-vs-publish from vite's command before any build/serve hook
3433
+ // runs: the dev server builds to .nrg and imports @bonsae/nrg, while a
3434
+ // production build writes ./dist and rewrites to @bonsae/nrg-runtime.
3435
+ // config() always runs before buildStart/configureServer.
3436
+ name: "vite-plugin-node-red:resolve-mode",
3437
+ config(_config, env) {
3438
+ buildContext.isDev = resolveIsDev(env);
3439
+ buildContext.outDir = buildContext.isDev ? resolvedDevOutDir : resolvedOutDir;
3440
+ }
3441
+ },
3423
3442
  serverPlugin({
3424
3443
  nodeRedLauncher,
3425
3444
  serverBuildOptions,