@navita/vite-plugin 2.0.1 → 2.0.2

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 (3) hide show
  1. package/package.json +3 -3
  2. package/remix.cjs +8 -5
  3. package/remix.mjs +8 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/vite-plugin",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Navita Vite Plugin",
5
5
  "keywords": [
6
6
  "vite",
@@ -22,8 +22,8 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@navita/core": "1.0.0",
26
- "@navita/css": "0.2.0"
25
+ "@navita/css": "0.2.0",
26
+ "@navita/core": "1.0.0"
27
27
  },
28
28
  "license": "MIT",
29
29
  "author": "Eagerpatch",
package/remix.cjs CHANGED
@@ -26,6 +26,7 @@ const remixServerBuildId = '\0virtual:remix/server-build';
26
26
  let cssFileName;
27
27
  function navitaRemix(options) {
28
28
  let isProduction = false;
29
+ let hasEmittedCss = false;
29
30
  const { renderChunk , ...navitaVite } = index.navita(options);
30
31
  return [
31
32
  navitaVite,
@@ -40,19 +41,20 @@ function navitaRemix(options) {
40
41
  }
41
42
  return `${code}\n${remixServerBuildExtension}`;
42
43
  },
43
- renderChunk (_, chunk) {
44
- if (chunk.name === "root") {
44
+ renderChunk (_, chunk, options) {
45
+ const isServerChunk = options.dir.endsWith('/server');
46
+ const isClientChunk = options.dir.endsWith('/client');
47
+ if (isClientChunk && chunk.name === "root") {
45
48
  // Generate a random name for the CSS file.
46
49
  // Vite uses a file hash as the name, but since the client build will finish before
47
50
  // the server build, we need to generate a random name for the CSS file.
48
51
  // Ideally we could use a hash, but since the server might contain more styles than the client, we need to do it like this.
49
52
  const random = crypto__namespace.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8);
50
53
  cssFileName = `assets/navita-${random}.css`;
51
- // Attach the file to the root chunk so that it's included in the client build.
52
- chunk.viteMetadata?.importedCss.add(cssFileName);
54
+ chunk.viteMetadata.importedCss.add(cssFileName);
53
55
  return;
54
56
  }
55
- if (chunk.name === 'server-build') {
57
+ if (isServerChunk && !hasEmittedCss) {
56
58
  // In the server-build, we'll generate the CSS and emit it as an asset.
57
59
  // Remix will then move it to the client assets.
58
60
  this.emitFile({
@@ -61,6 +63,7 @@ function navitaRemix(options) {
61
63
  type: 'asset',
62
64
  source: index.getRenderer()?.engine.renderCssToString()
63
65
  });
66
+ hasEmittedCss = true;
64
67
  }
65
68
  }
66
69
  }
package/remix.mjs CHANGED
@@ -5,6 +5,7 @@ const remixServerBuildId = '\0virtual:remix/server-build';
5
5
  let cssFileName;
6
6
  function navitaRemix(options) {
7
7
  let isProduction = false;
8
+ let hasEmittedCss = false;
8
9
  const { renderChunk , ...navitaVite } = navita(options);
9
10
  return [
10
11
  navitaVite,
@@ -19,19 +20,20 @@ function navitaRemix(options) {
19
20
  }
20
21
  return `${code}\n${remixServerBuildExtension}`;
21
22
  },
22
- renderChunk (_, chunk) {
23
- if (chunk.name === "root") {
23
+ renderChunk (_, chunk, options) {
24
+ const isServerChunk = options.dir.endsWith('/server');
25
+ const isClientChunk = options.dir.endsWith('/client');
26
+ if (isClientChunk && chunk.name === "root") {
24
27
  // Generate a random name for the CSS file.
25
28
  // Vite uses a file hash as the name, but since the client build will finish before
26
29
  // the server build, we need to generate a random name for the CSS file.
27
30
  // Ideally we could use a hash, but since the server might contain more styles than the client, we need to do it like this.
28
31
  const random = crypto.randomBytes(30).toString("base64").replace(/[^a-zA-Z0-9]/g, "").slice(0, 8);
29
32
  cssFileName = `assets/navita-${random}.css`;
30
- // Attach the file to the root chunk so that it's included in the client build.
31
- chunk.viteMetadata?.importedCss.add(cssFileName);
33
+ chunk.viteMetadata.importedCss.add(cssFileName);
32
34
  return;
33
35
  }
34
- if (chunk.name === 'server-build') {
36
+ if (isServerChunk && !hasEmittedCss) {
35
37
  // In the server-build, we'll generate the CSS and emit it as an asset.
36
38
  // Remix will then move it to the client assets.
37
39
  this.emitFile({
@@ -40,6 +42,7 @@ function navitaRemix(options) {
40
42
  type: 'asset',
41
43
  source: getRenderer()?.engine.renderCssToString()
42
44
  });
45
+ hasEmittedCss = true;
43
46
  }
44
47
  }
45
48
  }