-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add civet unplugin #632
Merged
Merged
Add civet unplugin #632
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8fbc0c9
Add civet unplugin
Mokshit06 891d990
Update docs
Mokshit06 79c6290
Stop dts and js from being true at same time
Mokshit06 94710fc
setup build for unplugin in root
Mokshit06 815ae69
Install unplugin-civet deps on build
Mokshit06 eedee6e
move unplugin deps to top level
Mokshit06 847e80c
webpack entrypoint
Mokshit06 eb4bd13
ts update config
Mokshit06 f377cd8
fix recursive build
Mokshit06 f3ac1cc
fix a few bugs
Mokshit06 2548ecd
add examples
Mokshit06 b7207c5
Merge branch 'main' of https://github.com/danielXMoore/Civet into unp…
Mokshit06 e918496
update examples import source
Mokshit06 525508e
setup examples correctly
Mokshit06 a751684
change any to unknown in type defs
Mokshit06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# unplugin-civet | ||
|
||
Use Civet in your projects with Vite, Webpack, Rspack, Rollup and esbuild, with `dts` generation supported. | ||
|
||
## Usage | ||
|
||
The only setup required is to install the plugin and adding it your bundler's config: | ||
|
||
```bash | ||
npm i -D unplugin-civet | ||
``` | ||
|
||
### Vite | ||
|
||
```ts | ||
// vite.config.ts | ||
import { defineConfig } from 'vite'; | ||
import civetVitePlugin from 'unplugin-civet/vite'; | ||
|
||
export default defineConfig({ | ||
// ... | ||
plugins: [ | ||
civetVitePlugin({ | ||
// options | ||
}), | ||
], | ||
}); | ||
``` | ||
|
||
### Rollup | ||
|
||
```ts | ||
// rollup.config.ts | ||
import civetRollupPlugin from 'unplugin-civet/rollup'; | ||
|
||
export default { | ||
// ... | ||
plugins: [ | ||
civetRollupPlugin({ | ||
// options | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
### ESBuild | ||
|
||
```ts | ||
import esbuild from 'esbuild'; | ||
import civetEsbuildPlugin from 'unplugin-civet/esbuild'; | ||
|
||
esbuild | ||
.build({ | ||
// ... | ||
plugins: [civetEsbuildPlugin()], | ||
}) | ||
.catch(() => process.exit(1)); | ||
``` | ||
|
||
### Webpack | ||
|
||
```js | ||
const civetWebpackPlugin = require('unplugin-civet/webpack'); | ||
|
||
module.exports = { | ||
// ... | ||
plugins: [ | ||
civetWebpackPlugin({ | ||
// options | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
## Options | ||
|
||
```ts | ||
interface PluginOptions { | ||
dts?: boolean; | ||
outputExtension?: string; | ||
js?: boolean; | ||
transformOutput?: ( | ||
code: string, | ||
id: string | ||
) => TransformResult | Promise<TransformResult>; | ||
} | ||
``` | ||
|
||
- `dts`: `unplugin-civet` also supports generating `.d.ts` type definition files from the civet source, which is useful for building libraries. | ||
- `outputExtension`: Output filename extension to use. Default: `.civet.jsx`, or `.civet.tsx` if `js` is `false`. | ||
- `js`: Whether to transpile to JS or TS. | ||
- `transformOutput`: Replace the `civet.compile` tranformer with a custom transformer. It gets passed the civet source and filename, and should return valid TS/JS code. | ||
edemaine marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you state the default here? I believe it's
false
, in which case should also rewrite the.civet.jsx
default foroutputExtension
. (Should be.civet.tsx
, unlessjs
istrue
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that should be corrected. Though now that I think of it, maybe
js
should be true by default. Most users would be using these for building applications and not libraries and in that case preserving types doesn't help much. I'm open to other opinions on thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A default of
js: true
would breakdts: true
. We could makedts
implyjs: false
, but honestlyjs: false
is safer; some TypeScript features are not correctly implemented by Civet withjs: true
, and it just costs a bit of time to use already existing TS integration. So I thinkjs: false
is best.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could give imply
js
based on the value ofdts
first,in which case both options should work. My main concern was that rollup and webpack can't process typescript without additional plugins, so would need to set
js: true
to make the setup work, but ifjs: false
has better typescript features then let's go with that default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can include the
{js: true}
in the README where we give recommended workflows for Webpack and Rollup?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can do that