|
| 1 | +import path from 'path' |
| 2 | + |
1 | 3 | import { defineConfig, transformWithEsbuild } from 'vite'
|
2 | 4 | import { nodePolyfills } from 'vite-plugin-node-polyfills'
|
3 | 5 | import { yamlPlugin } from 'esbuild-plugin-yaml'
|
@@ -35,12 +37,24 @@ fs.emptyDirSync('./tmp')
|
35 | 37 |
|
36 | 38 | // index.html is placed at the root of the repo for Vite to pick up.
|
37 | 39 | 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. |
38 | 41 | customFile('CUSTOM_CSS', './tmp/custom-styles.css', './example/example.css')
|
39 | 42 | 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 | +}) |
41 | 53 | // JS_CONFIG can be a single file or a folder.
|
42 | 54 | // 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. |
44 | 58 | customFile(
|
45 | 59 | 'JS_CONFIG',
|
46 | 60 | (file) => (file.endsWith('.js') ? './tmp/config.js' : './tmp/'),
|
|
0 commit comments