-
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 all commits
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
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,88 @@ | ||
# unplugin-civet | ||
|
||
Use Civet in your projects with Vite, Webpack, Rspack, Rollup and esbuild, with `dts` generation supported. | ||
|
||
## Usage | ||
|
||
The only setup required is adding it your bundler's config: | ||
|
||
### Vite | ||
|
||
```ts | ||
// vite.config.ts | ||
import { defineConfig } from 'vite'; | ||
import civetVitePlugin from '@danielx/civet/vite'; | ||
|
||
export default defineConfig({ | ||
// ... | ||
plugins: [ | ||
civetVitePlugin({ | ||
// options | ||
}), | ||
], | ||
}); | ||
``` | ||
|
||
### Rollup | ||
|
||
```ts | ||
// rollup.config.ts | ||
import civetRollupPlugin from '@danielx/civet/rollup'; | ||
|
||
export default { | ||
// ... | ||
plugins: [ | ||
civetRollupPlugin({ | ||
// options | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
### ESBuild | ||
|
||
```ts | ||
import esbuild from 'esbuild'; | ||
import civetEsbuildPlugin from '@danielx/civet/esbuild'; | ||
|
||
esbuild | ||
.build({ | ||
// ... | ||
plugins: [civetEsbuildPlugin()], | ||
}) | ||
.catch(() => process.exit(1)); | ||
``` | ||
|
||
### Webpack | ||
|
||
```js | ||
const civetWebpackPlugin = require('@danielx/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. Default: `false`. | ||
- `outputExtension`: Output filename extension to use. Default: `.civet.tsx`, or uses `.civet.jsx` if `js` is `true`. | ||
- `js`: Whether to transpile to JS or TS. Default: `false`. | ||
- `transformOutput(code, id)`: Adds a custom transformer over jsx/tsx code produced by `civet.compile`. It gets passed the jsx/tsx source (`code`) and filename (`id`), and should return valid jsx/tsx code. |
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,21 @@ | ||
# build output | ||
dist/ | ||
# generated types | ||
.astro/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
|
||
# environment variables | ||
.env | ||
.env.production | ||
|
||
# macOS-specific files | ||
.DS_Store |
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,4 @@ | ||
{ | ||
"recommendations": ["astro-build.astro-vscode"], | ||
"unwantedRecommendations": [] | ||
} |
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,11 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"command": "./node_modules/.bin/astro dev", | ||
"name": "Development server", | ||
"request": "launch", | ||
"type": "node-terminal" | ||
} | ||
] | ||
} |
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,47 @@ | ||
# Astro Starter Kit: Minimal | ||
|
||
``` | ||
npm create astro@latest -- --template minimal | ||
``` | ||
|
||
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/minimal) | ||
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/minimal) | ||
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/minimal/devcontainer.json) | ||
|
||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun! | ||
|
||
## 🚀 Project Structure | ||
|
||
Inside of your Astro project, you'll see the following folders and files: | ||
|
||
``` | ||
/ | ||
├── public/ | ||
├── src/ | ||
│ └── pages/ | ||
│ └── index.astro | ||
└── package.json | ||
``` | ||
|
||
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. | ||
|
||
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. | ||
|
||
Any static assets, like images, can be placed in the `public/` directory. | ||
|
||
## 🧞 Commands | ||
|
||
All commands are run from the root of the project, from a terminal: | ||
|
||
| Command | Action | | ||
| :------------------------ | :----------------------------------------------- | | ||
| `npm install` | Installs dependencies | | ||
| `npm run dev` | Starts local dev server at `localhost:3000` | | ||
| `npm run build` | Build your production site to `./dist/` | | ||
| `npm run preview` | Preview your build locally, before deploying | | ||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | | ||
| `npm run astro -- --help` | Get help using the Astro CLI | | ||
|
||
## 👀 Want to learn more? | ||
|
||
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). |
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,12 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import civetVitePlugin from '@danielx/civet/vite'; | ||
|
||
import solidJs from '@astrojs/solid-js'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
vite: { | ||
plugins: [civetVitePlugin({})], | ||
}, | ||
integrations: [solidJs()], | ||
}); |
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,20 @@ | ||
{ | ||
"name": "astro-example", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"dependencies": { | ||
"@astrojs/solid-js": "^2.2.0", | ||
"astro": "^2.10.7", | ||
"solid-js": "^1.7.11" | ||
}, | ||
"devDependencies": { | ||
"@danielx/civet": "*" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,10 @@ | ||
{createSignal} from 'solid-js' | ||
|
||
|
||
export default function Counter() | ||
[count, setCount] := createSignal 0 | ||
|
||
console.log "rendering" | ||
|
||
<button onClick={=>setCount(count() + 1)}> | ||
{count()} |
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 @@ | ||
/// <reference types="astro/client" /> |
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,17 @@ | ||
--- | ||
import Counter from '../component.civet'; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Astro</title> | ||
</head> | ||
<body> | ||
<h1>Astro</h1> | ||
<Counter client:load /> | ||
</body> | ||
</html> |
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,7 @@ | ||
{ | ||
"extends": "astro/tsconfigs/base", | ||
"compilerOptions": { | ||
"jsx": "preserve", | ||
"jsxImportSource": "solid-js" | ||
} | ||
} |
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,5 @@ | ||
{a} from "./utils/module.civet" | ||
|
||
export b = a | ||
|
||
export * from "./utils/module.civet" |
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,8 @@ | ||
{ | ||
"scripts": { | ||
"build": "npx rollup --config rollup.config.js" | ||
}, | ||
"devDependencies": { | ||
"@danielx/civet": "*" | ||
} | ||
edemaine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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,14 @@ | ||
import civetRollupPlugin from '@danielx/civet/rollup'; | ||
|
||
export default { | ||
input: 'main.civet', | ||
output: { | ||
dir: 'dist', | ||
format: 'cjs', | ||
}, | ||
plugins: [ | ||
civetRollupPlugin({ | ||
dts: true, | ||
}), | ||
], | ||
}; |
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,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "Node", | ||
"noEmit": false, | ||
"checkJs": false, | ||
"declarationMap": false, | ||
"skipLibCheck": true, | ||
"target": "ESNext", | ||
"allowJs": true, | ||
"jsx": "preserve", | ||
"emitDeclarationOnly": true, | ||
"declaration": true | ||
} | ||
} |
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 @@ | ||
export a = "a" |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<h1>Hello world</h1> | ||
<script src="./src/main.civet" type="module"></script> | ||
</body> | ||
</html> |
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,8 @@ | ||
{ | ||
"scripts": { | ||
"build": "npx vite build" | ||
}, | ||
"devDependencies": { | ||
"@danielx/civet": "*" | ||
} | ||
} |
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,3 @@ | ||
{a} from "./module.civet" | ||
|
||
console.log a |
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 @@ | ||
export a = "a" |
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,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "Node", | ||
"noEmit": false, | ||
"checkJs": false, | ||
"declarationMap": false, | ||
"skipLibCheck": true, | ||
"target": "ESNext", | ||
"allowJs": true, | ||
"jsx": "preserve", | ||
"emitDeclarationOnly": true, | ||
"declaration": true | ||
} | ||
} |
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,13 @@ | ||
import civetVitePlugin from '@danielx/civet/vite'; | ||
import { defineConfig } from 'vite'; | ||
|
||
export default defineConfig({ | ||
build: { | ||
lib: { | ||
entry: './src/main.civet', | ||
fileName: 'main', | ||
formats: ['cjs', 'es'], | ||
}, | ||
}, | ||
plugins: [civetVitePlugin({ dts: true })], | ||
}); |
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.
For Windows, I realize
chmod a-x dist/*.*[jt]s
would be helpful.Also, what is this new
dist/chunk-UZRN3RFA.mjs
file? Presumably it's not desired?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.
For the esm build, tsup splits the common chunks into a separate file by default. As all the bundler entrypoints
/esbuild
,/rollup
etc. import the centralcivetUnplugin
it splits that into this chunk and imports it in them. Mostly helps keep the bundle size smaller as its not duplicatedThere 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.
Ah, that is nice. Can we choose a better name for that file? Given that there's only one, maybe a custom name rule would work?
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 can choose a better name for it https://esbuild.github.io/api/#chunk-names, but i'm not sure if we should. There currently only exists one of these, but might be more than that in the future. I would suggest keeping it as is, or just turning off splitting
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.
I think it would be nice to rename it for now; we can always change it if we need multiple chunks in the future (seems unlikely for the unplugin?). Maybe
unplugin-shared
?