谢亚昕 4 months ago
commit
fa0bba3705
  1. 2
      .gitignore
  2. 3
      README.md
  3. 23
      build.config.ts
  4. 37
      package.json
  5. 2165
      pnpm-lock.yaml
  6. 3
      src/index.ts
  7. 3
      src/plugins/vite.ts
  8. 3
      src/plugins/webpack.ts

2
.gitignore

@ -0,0 +1,2 @@
node_modules
dist

3
README.md

@ -0,0 +1,3 @@
# Unbuild lib example
A simple example of how to generate ESM, CJS and DTS from TypeScript using a folder as entry point.

23
build.config.ts

@ -0,0 +1,23 @@
import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({
entries: [
"src/index.ts",
{
input: "src/plugins/",
outDir: "dist/plugins/",
format: "esm",
},
{
input: "src/plugins/",
outDir: "dist/plugins/",
format: "cjs",
ext: "cjs",
declaration: false,
},
],
declaration: true,
rollup: {
emitCJS: true,
},
});

37
package.json

@ -0,0 +1,37 @@
{
"name": "unbuild-example-mkdist",
"version": "1.0.0",
"type": "module",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./plugins/*": {
"import": {
"types": "./dist/plugins/*.d.mts",
"default": "./dist/plugins/*.mjs"
},
"require": {
"types": "./dist/plugins/*.d.cts",
"default": "./dist/plugins/*.cjs"
}
}
},
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"build:stub": "unbuild --stub"
},
"devDependencies": {
"unbuild": "^2.0.0"
}
}

2165
pnpm-lock.yaml

File diff suppressed because it is too large

3
src/index.ts

@ -0,0 +1,3 @@
export function main(data: string): string {
return `Hello ${data}!`;
}

3
src/plugins/vite.ts

@ -0,0 +1,3 @@
export default function vitePlugin(): string {
return "Hello Vite!";
}

3
src/plugins/webpack.ts

@ -0,0 +1,3 @@
export default function webpackPlugin(): string {
return "Hello Webpack!";
}
Loading…
Cancel
Save