2023-02-28 14:56:51 +00:00
|
|
|
import { resolve } from 'node:path'
|
|
|
|
import { defineConfig, normalizePath } from 'vite'
|
2022-11-16 13:36:09 +00:00
|
|
|
|
2023-11-13 18:06:58 +00:00
|
|
|
const file = normalizePath(resolve(__dirname, 'index.js'))
|
2022-11-16 13:36:09 +00:00
|
|
|
let transformCount = 1
|
|
|
|
|
|
|
|
const transformPlugin = {
|
|
|
|
name: 'transform',
|
2023-11-13 18:06:58 +00:00
|
|
|
load(id) {
|
|
|
|
if (id === file) {
|
|
|
|
// Ensure `index.js` is reloaded if 'plugin-dep-load.js' is changed
|
|
|
|
this.addWatchFile('./plugin-dep-load.js')
|
|
|
|
}
|
|
|
|
},
|
2022-11-16 13:36:09 +00:00
|
|
|
transform(code, id) {
|
2023-11-13 18:06:58 +00:00
|
|
|
if (id === file) {
|
2022-11-16 13:36:09 +00:00
|
|
|
// Ensure `index.js` is reevaluated if 'plugin-dep.js' is changed
|
|
|
|
this.addWatchFile('./plugin-dep.js')
|
|
|
|
|
|
|
|
return `
|
|
|
|
// Inject TRANSFORM_COUNT
|
|
|
|
let TRANSFORM_COUNT = ${transformCount++};
|
|
|
|
|
|
|
|
${code}
|
|
|
|
`
|
|
|
|
}
|
2022-12-04 07:19:06 +00:00
|
|
|
},
|
2022-11-16 13:36:09 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 14:56:51 +00:00
|
|
|
export default defineConfig({
|
2022-12-04 07:19:06 +00:00
|
|
|
plugins: [transformPlugin],
|
2023-02-28 14:56:51 +00:00
|
|
|
})
|