mermaid/vite.config.ts

35 lines
765 B
TypeScript
Raw Normal View History

2022-09-07 12:52:48 +05:30
import { Generator } from 'jison';
2022-09-07 11:24:40 +05:30
import { defineConfig } from 'vitest/config';
2022-09-07 12:52:48 +05:30
const fileRegex = /\.jison$/;
2022-09-07 11:24:40 +05:30
/** Transforms jison to js. */
export function jisonPlugin() {
return {
name: 'transform-jison',
transform(src: string, id: string) {
if (fileRegex.test(id)) {
2022-09-07 12:52:48 +05:30
console.log('Transforming', id);
2022-09-07 11:24:40 +05:30
return {
// @ts-ignore
2022-09-07 12:52:48 +05:30
code: new Generator(src, { 'token-stack': true }).generate(),
2022-09-07 11:24:40 +05:30
map: null, // provide source map if available
};
}
},
};
}
export default defineConfig({
resolve: {
extensions: ['.jison', '.js', '.ts', '.json'],
},
plugins: [jisonPlugin()],
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['src/tests/setup.ts'],
},
});