0.3.3 • Published 10 months ago
@hyrious/esbuild-plugin-svelte v0.3.3
@hyrious/esbuild-plugin-svelte
Minimal efforts to make svelte work in esbuild.
Install
npm add -D @hyrious/esbuild-plugin-svelte svelte esbuildUsage
import { build } from 'esbuild'
import { svelte } from '@hyrious/esbuild-plugin-svelte'
await build({
entryPoints: ['main.js'],
bundle: true,
plugins: [svelte()],
}).catch(() => process.exit(1))Options
svelte({
filter: /\.svelte(\?.*)?$/,
compilerOptions: {},
preprocess: [],
emitCss: true,
inspector: void 0,
dynamicCompileOptions: () => void 0,
})filter
Passed to esbuild onLoad()
callback to match svelte files.
compilerOptions
See svelte/compiler#CompileOptions.
If not specified, the dev mode is detected with the following logic:
- If either one of the following config is set,
dev: false.minify: truedefine: { 'process.env.NODE_ENV': '"production"' }define: { 'import.meta.env.NODE_ENV': '"production"' }define: { 'import.meta.env.DEV': 'false' }
- Otherwise,
dev: true.
If not specified, the ssr mode (generate: 'server') is detected with the following logic:
- If either one of the following config is set,
generate: 'server'.define: { 'import.meta.env.SSR': 'true' }
- Otherwise,
generate: 'client'.
preprocess
See svelte/compiler#Preprocessor.
You can opt-in the esbuild-powered TypeScript preprocessor by:
import { svelte, typescript } from '@hyrious/esbuild-plugin-svelte'
svelte({
// esbuild will print warnings on the final js, so suppress them here.
preprocess: [typescript({ onwarn: false })],
})emitCss
Generate virtual CSS files. If true (by default), it will set svelte compile
options css: 'external' automatically.
inspector
Enable svelte inspector during development (see the dev logic above).
You can set it to false to ensure it is not enabled anyway.
dynamicCompileOptions
A function to update compilerOptions before compilation.
svelte({
dynamicCompileOptions({ filename }) {
if (filename.includes('node_modules')) return { runes: false }
},
})Credits
Changelog
License
MIT @ hyrious