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