Created
March 21, 2023 05:30
-
-
Save mckoss/8c549a5f0e968e6a0415fdc8dd35ab5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { resolve } from 'path'; | |
import { defineConfig } from 'vite'; | |
// const rewriteImports = { | |
// name: 'rewrite-imports', | |
// transform(code: string, id: string) { | |
// console.log(`Processing ${id} ...`); | |
// if (id.endsWith('.js') || id.endsWith('.ts')) { | |
// const importRegex = /import (.*) from ['"]chai['"]/g; | |
// const replacement = "import $1 from './chai/index.js'"; | |
// return code.replace(importRegex, replacement); | |
// } | |
// }, | |
// }; | |
// Helper function to resolve paths relative to the project root. | |
function test(path: string) { | |
return resolve(__dirname, `src/tests/${path}`); | |
} | |
function btest(path: string) { | |
return resolve(__dirname, `src/browser-tests/${path}`); | |
} | |
export default defineConfig({ | |
// plugins: [rewriteImports], | |
base: './', | |
publicDir: false, | |
optimizeDeps: { | |
exclude: [ | |
"src/*.js" | |
], | |
}, | |
build: { | |
target: 'esnext', | |
sourcemap: true, | |
minify: false, | |
outDir: 'dist/scripts/browser-tests', | |
// Note the empty lib.entry field. I found I needed to list the entry points | |
// in the input option below, and lib was not | |
lib: { | |
entry: { | |
// 'test-points': test('test-points.ts'), | |
// 'test-racer-helper': test('test-racer-helper.ts'), | |
// 'test-racers': btest('test-racers.ts'), | |
}, | |
formats: ['es'], | |
}, | |
rollupOptions: { | |
// These options are not needed when using multiple entry points | |
// in the lib configuration. Where possible, dependent modules will | |
// include a reference to the exported module instead of bundling it | |
// into the module itself. | |
input: { | |
'test-points': test('test-points.ts'), | |
'test-racer-helper': test('test-racer-helper.ts'), | |
'test-racers': btest('test-racers.ts'), | |
// 'test-racetrack': btest('test-racetrack.ts'), | |
// 'test-tracks': btest('test-tracks.ts'), | |
}, | |
// output: { | |
// preserveModules: true, | |
// entryFileNames: '[name].js', | |
// }, | |
external: [ | |
'chai', | |
'../points.js', | |
'../racetrack.js', | |
/\.\.\/racers\/.*js/, | |
] | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment