Skip to content

Commit fb6a285

Browse files
committed
Support HMR for GLSL files
Now edits to GLSL files will cause dev server to automatically update the page, as expected. Previously only worked for the GLSL files directly imported by JS. Done by patching dependencies; should try to get some version of these changes merged upstream. See vitejs/vite#9723
1 parent e5cae02 commit fb6a285

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

patches/glslify+7.1.1.patch

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/node_modules/glslify/index.js b/node_modules/glslify/index.js
2+
index 7bb9ede..3942421 100644
3+
--- a/node_modules/glslify/index.js
4+
+++ b/node_modules/glslify/index.js
5+
@@ -45,7 +45,7 @@ function iface () {
6+
if (!opts) opts = {}
7+
var depper = gdeps(opts)
8+
var deps = depper.inline(src, opts.basedir || basedir)
9+
- return bundle(deps)
10+
+ return { source: bundle(deps), deps }
11+
}
12+
function file(filename, opts) {
13+
if (!opts) opts = {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/node_modules/rollup-plugin-glslify/index.js b/node_modules/rollup-plugin-glslify/index.js
2+
index 85474ec..2c1e423 100644
3+
--- a/node_modules/rollup-plugin-glslify/index.js
4+
+++ b/node_modules/rollup-plugin-glslify/index.js
5+
@@ -58,7 +58,12 @@ module.exports = function glslify(userOptions = {}) {
6+
options
7+
);
8+
9+
- code = compile(code, fileOptions);
10+
+ const { source, deps } = compile(code, fileOptions);
11+
+ code = source;
12+
+
13+
+ for (const dep of deps.filter(dep => !dep.entry)) {
14+
+ this.addWatchFile(dep.file);
15+
+ }
16+
17+
if (typeof options.compress === 'function') {
18+
code = options.compress(code);
19+
@@ -67,7 +72,7 @@ module.exports = function glslify(userOptions = {}) {
20+
}
21+
22+
return {
23+
- code: `export default ${JSON.stringify(code)}; // eslint-disable-line`,
24+
+ code: `export default ${JSON.stringify(source)}; // eslint-disable-line`,
25+
map: { mappings: '' }
26+
};
27+
}

patches/vite+3.0.9.patch

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/vite/dist/node/chunks/dep-0fc8e132.js b/node_modules/vite/dist/node/chunks/dep-0fc8e132.js
2-
index 54ffaf0..0ae10f7 100644
2+
index 54ffaf0..653c4d4 100644
33
--- a/node_modules/vite/dist/node/chunks/dep-0fc8e132.js
44
+++ b/node_modules/vite/dist/node/chunks/dep-0fc8e132.js
55
@@ -12002,6 +12002,10 @@ function copyDir(srcDir, destDir) {
@@ -24,3 +24,39 @@ index 54ffaf0..0ae10f7 100644
2424
if (headers) {
2525
for (const name in headers) {
2626
res.setHeader(name, headers[name]);
27+
@@ -40203,7 +40211,7 @@ function importAnalysisPlugin(config) {
28+
// properly finish the request with a 504 sent to the browser.
29+
throwOutdatedRequest(importer);
30+
}
31+
- if (!imports.length) {
32+
+ if (!imports.length && !this._addedImports) {
33+
importerModule.isSelfAccepting = false;
34+
isDebug$1 &&
35+
debug$7(`${timeFrom(start)} ${picocolors.exports.dim(`[no imports] ${prettyImporter}`)}`);
36+
@@ -40224,7 +40232,7 @@ function importAnalysisPlugin(config) {
37+
? new Map()
38+
: null;
39+
const toAbsoluteUrl = (url) => path$n.posix.resolve(path$n.posix.dirname(importerModule.url), url);
40+
- const normalizeUrl = async (url, pos) => {
41+
+ const normalizeUrl = async (url, pos, forceSkipImportAnalysis) => {
42+
if (base !== '/' && url.startsWith(base)) {
43+
url = url.replace(base, '/');
44+
}
45+
@@ -40303,7 +40311,7 @@ function importAnalysisPlugin(config) {
46+
// up-to-date version of this module.
47+
try {
48+
// delay setting `isSelfAccepting` until the file is actually used (#7870)
49+
- const depModule = await moduleGraph.ensureEntryFromUrl(url, ssr, canSkipImportAnalysis(url));
50+
+ const depModule = await moduleGraph.ensureEntryFromUrl(url, ssr, canSkipImportAnalysis(url) || forceSkipImportAnalysis);
51+
if (depModule.lastHMRTimestamp > 0) {
52+
url = injectQuery(url, `t=${depModule.lastHMRTimestamp}`);
53+
}
54+
@@ -40518,7 +40526,7 @@ function importAnalysisPlugin(config) {
55+
// attached by pluginContainer.addWatchFile
56+
const pluginImports = this._addedImports;
57+
if (pluginImports) {
58+
- (await Promise.all([...pluginImports].map((id) => normalizeUrl(id, 0)))).forEach(([url]) => importedUrls.add(url));
59+
+ (await Promise.all([...pluginImports].map((id) => normalizeUrl(id, 0, true)))).forEach(([url]) => importedUrls.add(url));
60+
}
61+
// HMR transforms are no-ops in SSR, so an `accept` call will
62+
// never be injected. Avoid updating the `isSelfAccepting`

0 commit comments

Comments
 (0)