Skip to content

Commit 76969a0

Browse files
build(vite): Don't rename copied graphql files.
1 parent 66f7777 commit 76969a0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

vite.config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
13
import { defineConfig, transformWithEsbuild } from 'vite'
24
import { nodePolyfills } from 'vite-plugin-node-polyfills'
35
import { yamlPlugin } from 'esbuild-plugin-yaml'
@@ -35,12 +37,24 @@ fs.emptyDirSync('./tmp')
3537

3638
// index.html is placed at the root of the repo for Vite to pick up.
3739
customFile('HTML_FILE', './index.html', './lib/index.tpl.html')
40+
// The CSS and YML file are copied with a fixed name, that name is being used for import.
3841
customFile('CUSTOM_CSS', './tmp/custom-styles.css', './example/example.css')
3942
customFile('YAML_CONFIG', './tmp/config.yml', './example/example-config.yml')
40-
customFile('PLAN_QUERY_RESOURCE_URI', './tmp/planQuery.graphql')
43+
// Don't rename the .graphql file because, if used, the original name is referenced in one of the JS files.
44+
// Constraint: the .graphql file must be in the same original folder as config.js (see below).
45+
customFile('PLAN_QUERY_RESOURCE_URI', (file) => {
46+
const fileParts = file.split(path.sep)
47+
if (fileParts.length > 0) {
48+
const fileName = fileParts[fileParts.length - 1]
49+
return `./tmp/${fileName}`
50+
}
51+
return './tmp/'
52+
})
4153
// JS_CONFIG can be a single file or a folder.
4254
// If using a folder, its content (including subfolders) will be copied into ./tmp/.
43-
// That folder should contain a config.js file and not contain any of the other custom files above.
55+
// Constraint: That folder should contain a config.js file and not contain any of the other custom files above.
56+
// Alternately, if the folder that holds the JS config files also contains the graphql file,
57+
// you can try passing JS_CONFIG as a folder and omit PLAN_QUERY_RESOURCE_URI.
4458
customFile(
4559
'JS_CONFIG',
4660
(file) => (file.endsWith('.js') ? './tmp/config.js' : './tmp/'),

0 commit comments

Comments
 (0)