Skip to content

Commit

Permalink
Merge pull request #45 from vite-plugin/v1.2.7
Browse files Browse the repository at this point in the history
V1.2.7
  • Loading branch information
caoxiemeihao committed Jan 20, 2023
2 parents 01870bf + ca2fccc commit 86901e6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ package-lock.json
pnpm-lock.yaml
yarn.lock

/types
/index.cjs
/index.js
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2023-01-20] v1.2.7

- 53ecc11 feat: generate types #44

## [2023-01-13] v1.2.6

- 3a4bfd9 fix: recursively up lookup of `node_moduels` #41
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "vite-plugin-dynamic-import",
"version": "1.2.6",
"version": "1.2.7",
"description": "Enhance Vite builtin dynamic import",
"type": "module",
"main": "index.js",
"types": "src",
"types": "types",
"exports": {
".": {
"import": "./index.js",
Expand All @@ -21,6 +21,7 @@
"dev": "vite build --watch",
"build": "vite build",
"test": "vite -c test/vite.config.ts",
"types": "tsc",
"prepublishOnly": "npm run build"
},
"dependencies": {
Expand All @@ -39,7 +40,7 @@
"dynamic"
],
"files": [
"src",
"types",
"index.cjs",
"index.js"
]
Expand Down
17 changes: 9 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"target": "ES2019",
"module": "CommonJS",
"target": "ES2022",
"module": "ESNext",
"esModuleInterop": true,
"moduleResolution": "Node",
"resolveJsonModule": true,
"strict": true,
"allowJs": true,
"jsx": "preserve",
"baseUrl": ".",
"outDir": "dist",
"declaration": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strict": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"outDir": "types",
"emitDeclarationOnly": true
},
"include": ["src/**/*.ts"]
"include": ["src"]
}
28 changes: 25 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import path from 'path'
import { builtinModules } from 'module'
import fs from 'node:fs'
import path from 'node:path'
import { spawn } from 'node:child_process'
import { builtinModules } from 'node:module'
import { defineConfig } from 'vite'
import pkg from './package.json'

export default defineConfig({
build: {
emptyOutDir: false,
minify: false,
outDir: '',
emptyOutDir: false,
target: 'node14',
lib: {
entry: path.join(__dirname, 'src/index.ts'),
Expand All @@ -28,3 +30,23 @@ export default defineConfig({
},
},
})

function generateTypes() {
return new Promise(resolve => {
const cp = spawn(
process.platform === 'win32' ? 'npm.cmd' : 'npm',
['run', 'types'],
{ stdio: 'inherit' },
)
cp.on('exit', code => {
!code && console.log('[types]', 'declaration generated')
resolve(code)
})
cp.on('error', process.exit)
})
}

if (process.env.NODE_ENV !== 'test') {
fs.rmSync('types', { recursive: true, force: true })
generateTypes()
}

0 comments on commit 86901e6

Please sign in to comment.