Use Civet in your projects with Vite, Webpack, Rspack, Rollup and esbuild, with dts
generation supported.
The only setup required is adding it your bundler's config:
// vite.config.ts
import { defineConfig } from 'vite';
import civetVitePlugin from '@danielx/civet/vite';
export default defineConfig({
// ...
plugins: [
civetVitePlugin({
// options
}),
],
});
// astro.config.ts
import { defineConfig } from 'astro/config';
import civet from '@danielx/civet/astro';
// https://astro.build/config
export default defineConfig({
// ...
integrations: [
civet({
// options
}),
],
});
// rollup.config.ts
import civetRollupPlugin from '@danielx/civet/rollup';
export default {
// ...
plugins: [
civetRollupPlugin({
// options
}),
],
};
import esbuild from 'esbuild';
import civetEsbuildPlugin from '@danielx/civet/esbuild';
esbuild
.build({
// ...
// sourcemap: true, // build and link sourcemap files
plugins: [civetEsbuildPlugin()],
})
.catch(() => process.exit(1));
const civetWebpackPlugin = require('@danielx/civet/webpack').default;
module.exports = {
// ...
plugins: [
civetWebpackPlugin({
// options
}),
],
};
interface PluginOptions {
emitDeclaration?: boolean;
implicitExtension?: boolean;
outputExtension?: string;
ts?: 'civet' | 'esbuild' | 'tsc' | 'preserve';
typecheck?: boolean | string;
comptime?: boolean;
transformOutput?: (
code: string,
id: string
) => TransformResult | Promise<TransformResult>;
}
emitDeclaration
: Whether to generate.d.ts
type definition files from the Civet source, which is useful for building libraries. Default:false
. (Requires installingtypescript
.)typecheck
: Whether to run type checking on the generated code. (Requires installingtypescript
.) Default:false
.- Specifying
true
aborts the build (with an error code) on TypeScript errors. - Alternatively, you can specify a string with any combination of
error
,warning
,suggestion
, ormessage
to specify which diagnostics abort the build. For example,"none"
ignores all diagnostics,"error+warning"
aborts on errors and warnings, and"all"
aborts on all diagnostics.
- Specifying
implicitExtension
: Whether to allow importingfilename.civet
viaimport "filename"
. Default:true
.outputExtension
: Output filename extension to append to.civet
. Default:".jsx"
, or".tsx"
ifts
is"preserve"
.ts
: Mode for transpiling TypeScript features into JavaScript. Default:"civet"
. Options:"civet"
: Use Civet's JS mode. (Not all TS features supported.)"esbuild"
: Use esbuild's transpiler. (Fast and more complete. Requires installingesbuild
.)"tsc"
: Use the TypeScript compiler. (Slow but complete. Requires installingtypescript
.)"preserve"
: Don't transpile TS code. Some bundlers, like esbuild and Vite, can handle TS directly. Also useful when usingtransformOutput
to handle TS code, or using a plugin that modifies TS AST. Note that some bundlers require additional plugins to handle TS. For example, for Webpack, you would need to installts-loader
and add it to your webpack config. Unfortunately, Rollup's TypeScript plugin is incompatible with this plugin, so you need to setts
to another option.
comptime
: Whether to evaluatecomptime
blocks at compile time. Default:false
.transformOutput(code, id)
: Adds a custom transformer over jsx/tsx code produced bycivet.compile
. It gets passed the jsx/tsx source (code
) and filename (id
), and should return valid jsx/tsx code.