@navita/vite-plugin 1.0.0 → 1.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/index.cjs +27 -18
  2. package/index.mjs +27 -18
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -23,12 +23,13 @@ function _interopNamespaceDefault(e) {
23
23
 
24
24
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
25
25
 
26
- let renderer;
27
26
  /*
28
27
  Some information for anyone wondering why we have duplicate css for the initial load
29
28
  during development in remix.
30
29
  https://github.com/remix-run/remix/discussions/8070#discussioncomment-7625870
31
- */ const VIRTUAL_CSS_NAME = '\0virtual:navita.css';
30
+ */ let renderer;
31
+ const VIRTUAL_MODULE_ID = 'virtual:navita.css';
32
+ const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
32
33
  function navita(options) {
33
34
  const importMap = [
34
35
  ...css.importMap,
@@ -38,11 +39,18 @@ function navita(options) {
38
39
  let lastCssContent;
39
40
  let context;
40
41
  let isSSR = false;
42
+ let isDEV = true;
41
43
  return {
42
- name: "navita",
43
44
  enforce: "pre",
44
- config () {
45
+ name: "navita",
46
+ config (_, env) {
47
+ isDEV = env.command === 'serve';
45
48
  return {
49
+ optimizeDeps: {
50
+ include: isDEV ? [
51
+ '@navita/css'
52
+ ] : []
53
+ },
46
54
  ssr: {
47
55
  external: [
48
56
  '@navita/css',
@@ -60,9 +68,12 @@ function navita(options) {
60
68
  server = _server;
61
69
  },
62
70
  async buildStart () {
71
+ if (renderer) {
72
+ return;
73
+ }
63
74
  const defaultEngineOptions = {
64
- enableSourceMaps: !!server,
65
- enableDebugIdentifiers: !!server,
75
+ enableSourceMaps: isDEV,
76
+ enableDebugIdentifiers: isDEV,
66
77
  ...options?.engineOptions || {}
67
78
  };
68
79
  renderer = createRenderer.createRenderer({
@@ -78,15 +89,14 @@ function navita(options) {
78
89
  }
79
90
  });
80
91
  },
81
- async resolveId (id) {
82
- if (id === VIRTUAL_CSS_NAME) {
83
- return VIRTUAL_CSS_NAME;
92
+ resolveId (source) {
93
+ if (source === VIRTUAL_MODULE_ID) {
94
+ return RESOLVED_VIRTUAL_MODULE_ID;
84
95
  }
85
- return;
86
96
  },
87
- async load (id) {
88
- if (id === VIRTUAL_CSS_NAME) {
89
- return lastCssContent;
97
+ async load (source) {
98
+ if (source === RESOLVED_VIRTUAL_MODULE_ID) {
99
+ return renderer.engine.renderCssToString();
90
100
  }
91
101
  return;
92
102
  },
@@ -102,8 +112,7 @@ function navita(options) {
102
112
  });
103
113
  const newCssContent = renderer.engine.renderCssToString();
104
114
  if (lastCssContent !== newCssContent) {
105
- invalidateModule(VIRTUAL_CSS_NAME);
106
- this.addWatchFile(VIRTUAL_CSS_NAME);
115
+ invalidateModule(RESOLVED_VIRTUAL_MODULE_ID);
107
116
  lastCssContent = newCssContent;
108
117
  for (const file of dependencies){
109
118
  if (!file.includes('node_modules')) {
@@ -113,16 +122,16 @@ function navita(options) {
113
122
  }
114
123
  }
115
124
  return {
116
- code: `${result} import "${VIRTUAL_CSS_NAME}";`,
125
+ code: `${result}\nimport "${VIRTUAL_MODULE_ID}";`,
117
126
  map: sourceMap
118
127
  };
119
128
  },
120
- renderChunk (_, chunk, third) {
129
+ renderChunk (_, chunk) {
121
130
  if (isSSR) {
122
131
  return;
123
132
  }
124
133
  for (const id of Object.keys(chunk.modules)){
125
- if (id.startsWith(VIRTUAL_CSS_NAME)) {
134
+ if (id.startsWith(RESOLVED_VIRTUAL_MODULE_ID)) {
126
135
  delete chunk.modules[id];
127
136
  }
128
137
  }
package/index.mjs CHANGED
@@ -2,12 +2,13 @@ import * as fs from 'node:fs';
2
2
  import { createRenderer } from '@navita/core/createRenderer';
3
3
  import { importMap } from '@navita/css';
4
4
 
5
- let renderer;
6
5
  /*
7
6
  Some information for anyone wondering why we have duplicate css for the initial load
8
7
  during development in remix.
9
8
  https://github.com/remix-run/remix/discussions/8070#discussioncomment-7625870
10
- */ const VIRTUAL_CSS_NAME = '\0virtual:navita.css';
9
+ */ let renderer;
10
+ const VIRTUAL_MODULE_ID = 'virtual:navita.css';
11
+ const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
11
12
  function navita(options) {
12
13
  const importMap$1 = [
13
14
  ...importMap,
@@ -17,11 +18,18 @@ function navita(options) {
17
18
  let lastCssContent;
18
19
  let context;
19
20
  let isSSR = false;
21
+ let isDEV = true;
20
22
  return {
21
- name: "navita",
22
23
  enforce: "pre",
23
- config () {
24
+ name: "navita",
25
+ config (_, env) {
26
+ isDEV = env.command === 'serve';
24
27
  return {
28
+ optimizeDeps: {
29
+ include: isDEV ? [
30
+ '@navita/css'
31
+ ] : []
32
+ },
25
33
  ssr: {
26
34
  external: [
27
35
  '@navita/css',
@@ -39,9 +47,12 @@ function navita(options) {
39
47
  server = _server;
40
48
  },
41
49
  async buildStart () {
50
+ if (renderer) {
51
+ return;
52
+ }
42
53
  const defaultEngineOptions = {
43
- enableSourceMaps: !!server,
44
- enableDebugIdentifiers: !!server,
54
+ enableSourceMaps: isDEV,
55
+ enableDebugIdentifiers: isDEV,
45
56
  ...options?.engineOptions || {}
46
57
  };
47
58
  renderer = createRenderer({
@@ -57,15 +68,14 @@ function navita(options) {
57
68
  }
58
69
  });
59
70
  },
60
- async resolveId (id) {
61
- if (id === VIRTUAL_CSS_NAME) {
62
- return VIRTUAL_CSS_NAME;
71
+ resolveId (source) {
72
+ if (source === VIRTUAL_MODULE_ID) {
73
+ return RESOLVED_VIRTUAL_MODULE_ID;
63
74
  }
64
- return;
65
75
  },
66
- async load (id) {
67
- if (id === VIRTUAL_CSS_NAME) {
68
- return lastCssContent;
76
+ async load (source) {
77
+ if (source === RESOLVED_VIRTUAL_MODULE_ID) {
78
+ return renderer.engine.renderCssToString();
69
79
  }
70
80
  return;
71
81
  },
@@ -81,8 +91,7 @@ function navita(options) {
81
91
  });
82
92
  const newCssContent = renderer.engine.renderCssToString();
83
93
  if (lastCssContent !== newCssContent) {
84
- invalidateModule(VIRTUAL_CSS_NAME);
85
- this.addWatchFile(VIRTUAL_CSS_NAME);
94
+ invalidateModule(RESOLVED_VIRTUAL_MODULE_ID);
86
95
  lastCssContent = newCssContent;
87
96
  for (const file of dependencies){
88
97
  if (!file.includes('node_modules')) {
@@ -92,16 +101,16 @@ function navita(options) {
92
101
  }
93
102
  }
94
103
  return {
95
- code: `${result} import "${VIRTUAL_CSS_NAME}";`,
104
+ code: `${result}\nimport "${VIRTUAL_MODULE_ID}";`,
96
105
  map: sourceMap
97
106
  };
98
107
  },
99
- renderChunk (_, chunk, third) {
108
+ renderChunk (_, chunk) {
100
109
  if (isSSR) {
101
110
  return;
102
111
  }
103
112
  for (const id of Object.keys(chunk.modules)){
104
- if (id.startsWith(VIRTUAL_CSS_NAME)) {
113
+ if (id.startsWith(RESOLVED_VIRTUAL_MODULE_ID)) {
105
114
  delete chunk.modules[id];
106
115
  }
107
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navita/vite-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Navita Vite Plugin",
5
5
  "keywords": [
6
6
  "vite",
@@ -17,8 +17,8 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@navita/css": "0.2.0",
21
- "@navita/core": "1.0.0"
20
+ "@navita/core": "1.0.0",
21
+ "@navita/css": "0.2.0"
22
22
  },
23
23
  "license": "MIT",
24
24
  "author": "Eagerpatch",