Skip to content

Commit a1da3f9

Browse files
authoredJan 23, 2025··
feat: add modified unplugin starter project content (#9)
1 parent e4dff16 commit a1da3f9

21 files changed

+983
-16
lines changed
 

‎eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import perfectionist from 'eslint-plugin-perfectionist'
44
export default antfu(
55
{
66
formatters: {
7+
html: 'prettier',
78
markdown: 'prettier',
89
},
910

‎package.json

+64-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,60 @@
3737
"esbuild",
3838
"rspack"
3939
],
40+
"exports": {
41+
".": {
42+
"import": "./dist/index.js",
43+
"require": "./dist/index.cjs"
44+
},
45+
"./astro": {
46+
"import": "./dist/astro.js",
47+
"require": "./dist/astro.cjs"
48+
},
49+
"./rspack": {
50+
"import": "./dist/rspack.js",
51+
"require": "./dist/rspack.cjs"
52+
},
53+
"./vite": {
54+
"import": "./dist/vite.js",
55+
"require": "./dist/vite.cjs"
56+
},
57+
"./webpack": {
58+
"import": "./dist/webpack.js",
59+
"require": "./dist/webpack.cjs"
60+
},
61+
"./rollup": {
62+
"import": "./dist/rollup.js",
63+
"require": "./dist/rollup.cjs"
64+
},
65+
"./esbuild": {
66+
"import": "./dist/esbuild.js",
67+
"require": "./dist/esbuild.cjs"
68+
},
69+
"./nuxt": {
70+
"import": "./dist/nuxt.js",
71+
"require": "./dist/nuxt.cjs"
72+
},
73+
"./farm": {
74+
"import": "./dist/farm.js",
75+
"require": "./dist/farm.cjs"
76+
},
77+
"./types": {
78+
"import": "./dist/types.js",
79+
"require": "./dist/types.cjs"
80+
},
81+
"./*": "./*"
82+
},
83+
"main": "dist/index.cjs",
84+
"module": "dist/index.js",
85+
"types": "dist/index.d.ts",
86+
"typesVersions": {
87+
"*": {
88+
"*": [
89+
"./dist/*",
90+
"./*"
91+
]
92+
}
93+
},
4094
"files": [
4195
"dist"
4296
],
@@ -45,8 +99,12 @@
4599
"pnpm": "9"
46100
},
47101
"scripts": {
102+
"build": "tsup",
103+
"dev": "tsup --watch src",
104+
"build:post": "esno scripts/postbuild.ts",
48105
"lint": "eslint .",
49-
"lint:fix": "run-s \"lint --fix\""
106+
"lint:fix": "run-s \"lint --fix\"",
107+
"playground": "pnpm -C playground run dev"
50108
},
51109
"peerDependencies": {
52110
"@farmfe/core": ">=1",
@@ -90,7 +148,11 @@
90148
"eslint": "~9.18.0",
91149
"eslint-plugin-format": "~1.0.1",
92150
"eslint-plugin-perfectionist": "~4.7.0",
151+
"esno": "~4.8.0",
152+
"fast-glob": "~3.3.3",
93153
"npm-run-all2": "~7.0.2",
94-
"typescript": "~5.7.3"
154+
"tsup": "~8.3.5",
155+
"typescript": "~5.7.3",
156+
"unplugin": "~2.1.2"
95157
}
96158
}

‎playground/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<a
11+
href="/__inspect/#/module?id=./main.ts&index=2"
12+
target="_blank"
13+
style="text-decoration: none; margin-top: 10px; display: block"
14+
>visit /__inspect/ to inspect the intermediate state</a
15+
>
16+
<script type="module" src="./main.ts"></script>
17+
</body>
18+
</html>

‎playground/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.getElementById('app')!.innerHTML = '__UNPLUGIN__'

‎playground/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "gltf-type-toolkit-playground",
3+
"type": "module",
4+
"private": true,
5+
"scripts": {
6+
"dev": "nodemon -w '../src/**/*.ts' -e .ts -x vite"
7+
},
8+
"devDependencies": {
9+
"vite": "~6.0.11",
10+
"vite-plugin-inspect": "~10.1.0"
11+
}
12+
}

‎playground/vite.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'vite'
2+
import Inspect from 'vite-plugin-inspect'
3+
import Unplugin from '../src/vite.js'
4+
5+
export default defineConfig({
6+
plugins: [
7+
Inspect(),
8+
Unplugin(),
9+
],
10+
})

‎pnpm-lock.yaml

+756-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- playground

‎scripts/postbuild.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { promises as fs } from 'node:fs'
2+
import { basename, dirname, resolve } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import chalk from 'chalk'
5+
import fg from 'fast-glob'
6+
7+
async function run(): Promise<void> {
8+
// fix cjs exports
9+
const files = await fg('*.cjs', {
10+
absolute: true,
11+
cwd: resolve(dirname(fileURLToPath(import.meta.url)), '../dist'),
12+
ignore: ['chunk-*'],
13+
})
14+
for (const file of files) {
15+
console.log(chalk.cyan.inverse(' POST '), `Fix ${basename(file)}`)
16+
let code = await fs.readFile(file, 'utf8')
17+
code = code.replace('exports.default =', 'module.exports =')
18+
code += 'exports.default = module.exports;'
19+
await fs.writeFile(file, code)
20+
}
21+
}
22+
23+
run()

‎src/astro.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Options } from './types'
2+
3+
import unplugin from './index.js'
4+
5+
export default (options: Options): any => ({
6+
hooks: {
7+
'astro:config:setup': async (astro: any) => {
8+
astro.config.vite.plugins ||= []
9+
astro.config.vite.plugins.push(unplugin.vite(options))
10+
},
11+
},
12+
name: 'unplugin-starter',
13+
})

‎src/esbuild.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createEsbuildPlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createEsbuildPlugin(unpluginFactory)

‎src/farm.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createFarmPlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createFarmPlugin(unpluginFactory)

‎src/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { UnpluginFactory } from 'unplugin'
2+
import type { Options } from './types'
3+
import { createUnplugin } from 'unplugin'
4+
5+
export const unpluginFactory: UnpluginFactory<Options | undefined> = options => ({
6+
name: 'unplugin-starter',
7+
transform(code) {
8+
return code.replace('__UNPLUGIN__', `Hello Unplugin! ${options}`)
9+
},
10+
transformInclude(id) {
11+
return id.endsWith('main.ts')
12+
},
13+
})
14+
15+
export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)
16+
17+
export default unplugin

‎src/nuxt.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Options } from './types'
2+
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'
3+
import vite from './vite.js'
4+
import webpack from './webpack.js'
5+
import '@nuxt/schema'
6+
7+
export interface ModuleOptions extends Options {
8+
9+
}
10+
11+
export default defineNuxtModule<ModuleOptions>({
12+
defaults: {
13+
// ...default options
14+
},
15+
meta: {
16+
configKey: 'unpluginStarter',
17+
name: 'nuxt-unplugin-starter',
18+
},
19+
setup(options, _nuxt) {
20+
addVitePlugin(() => vite(options))
21+
addWebpackPlugin(() => webpack(options))
22+
23+
// ...
24+
},
25+
})

‎src/rollup.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createRollupPlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createRollupPlugin(unpluginFactory)

‎src/rspack.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createRspackPlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createRspackPlugin(unpluginFactory)

‎src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface Options {
2+
// define your plugin options here
3+
}

‎src/vite.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createVitePlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createVitePlugin(unpluginFactory)

‎src/webpack.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createWebpackPlugin } from 'unplugin'
2+
import { unpluginFactory } from './index.js'
3+
4+
export default createWebpackPlugin(unpluginFactory)

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2017",
3+
"target": "es2022",
44
"lib": ["esnext", "DOM"],
55
"module": "esnext",
66
"moduleResolution": "node",

‎tsup.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Options } from 'tsup'
2+
3+
export default <Options>{
4+
cjsInterop: true,
5+
clean: true,
6+
dts: true,
7+
entry: [
8+
'src/*.ts',
9+
],
10+
format: ['cjs', 'esm'],
11+
onSuccess: 'pnpm run build:post',
12+
splitting: true,
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.