@navita/vite-plugin 2.0.0 → 2.0.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 (3) hide show
  1. package/package.json +1 -1
  2. package/remix.cjs +19 -24
  3. package/remix.mjs +20 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/vite-plugin",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Navita Vite Plugin",
5
5
  "keywords": [
6
6
  "vite",
package/remix.cjs CHANGED
@@ -22,37 +22,23 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
24
24
 
25
+ const remixServerBuildId = '\0virtual:remix/server-build';
25
26
  let cssFileName;
26
27
  function navitaRemix(options) {
27
- let server;
28
+ let isProduction = false;
28
29
  const { renderChunk , ...navitaVite } = index.navita(options);
29
30
  return [
30
31
  navitaVite,
31
32
  {
32
33
  name: 'navita-remix',
33
- configureServer (_server) {
34
- server = _server;
35
- server.middlewares.use(async function middleware(_req, _res, next) {
36
- try {
37
- const build = await server.ssrLoadModule('virtual:remix/server-build');
38
- const { module } = build.routes.root;
39
- // We modify the root module, to automatically include the CSS
40
- // when running the dev server.
41
- build.routes.root.module = {
42
- ...module,
43
- links: ()=>[
44
- ...module.links(),
45
- {
46
- rel: 'stylesheet',
47
- href: `/${index.VIRTUAL_MODULE_ID}`
48
- }
49
- ]
50
- };
51
- } catch (e) {
52
- console.error(e);
53
- }
54
- next();
55
- });
34
+ configResolved (config) {
35
+ isProduction = config.mode === 'production';
36
+ },
37
+ transform (code, id) {
38
+ if (isProduction || id !== remixServerBuildId) {
39
+ return;
40
+ }
41
+ return `${code}\n${remixServerBuildExtension}`;
56
42
  },
57
43
  renderChunk (_, chunk) {
58
44
  if (chunk.name === "root") {
@@ -80,5 +66,14 @@ function navitaRemix(options) {
80
66
  }
81
67
  ];
82
68
  }
69
+ const remixServerBuildExtension = `
70
+ routes.root.module = {
71
+ ...route0,
72
+ links: () => [
73
+ ...(route0.links ? route0.links() : []),
74
+ { rel: 'stylesheet', href: '/${index.VIRTUAL_MODULE_ID}' },
75
+ ],
76
+ };
77
+ `;
83
78
 
84
79
  exports.navitaRemix = navitaRemix;
package/remix.mjs CHANGED
@@ -1,37 +1,23 @@
1
1
  import * as crypto from 'node:crypto';
2
- import { navita, VIRTUAL_MODULE_ID, getRenderer } from './index.mjs';
2
+ import { navita, getRenderer, VIRTUAL_MODULE_ID } from './index.mjs';
3
3
 
4
+ const remixServerBuildId = '\0virtual:remix/server-build';
4
5
  let cssFileName;
5
6
  function navitaRemix(options) {
6
- let server;
7
+ let isProduction = false;
7
8
  const { renderChunk , ...navitaVite } = navita(options);
8
9
  return [
9
10
  navitaVite,
10
11
  {
11
12
  name: 'navita-remix',
12
- configureServer (_server) {
13
- server = _server;
14
- server.middlewares.use(async function middleware(_req, _res, next) {
15
- try {
16
- const build = await server.ssrLoadModule('virtual:remix/server-build');
17
- const { module } = build.routes.root;
18
- // We modify the root module, to automatically include the CSS
19
- // when running the dev server.
20
- build.routes.root.module = {
21
- ...module,
22
- links: ()=>[
23
- ...module.links(),
24
- {
25
- rel: 'stylesheet',
26
- href: `/${VIRTUAL_MODULE_ID}`
27
- }
28
- ]
29
- };
30
- } catch (e) {
31
- console.error(e);
32
- }
33
- next();
34
- });
13
+ configResolved (config) {
14
+ isProduction = config.mode === 'production';
15
+ },
16
+ transform (code, id) {
17
+ if (isProduction || id !== remixServerBuildId) {
18
+ return;
19
+ }
20
+ return `${code}\n${remixServerBuildExtension}`;
35
21
  },
36
22
  renderChunk (_, chunk) {
37
23
  if (chunk.name === "root") {
@@ -59,5 +45,14 @@ function navitaRemix(options) {
59
45
  }
60
46
  ];
61
47
  }
48
+ const remixServerBuildExtension = `
49
+ routes.root.module = {
50
+ ...route0,
51
+ links: () => [
52
+ ...(route0.links ? route0.links() : []),
53
+ { rel: 'stylesheet', href: '/${VIRTUAL_MODULE_ID}' },
54
+ ],
55
+ };
56
+ `;
62
57
 
63
58
  export { navitaRemix };