Skip to content

Commit

Permalink
build: make ESM/CJS dual package
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Aug 26, 2022
1 parent f0d9ce6 commit c39e502
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 22 deletions.
16 changes: 12 additions & 4 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
"name": "vite-plugin-checker",
"version": "0.4.9",
"description": "Vite plugin that runs TypeScript type checker on a separate process.",
"types": "./dist/esm/main.d.ts",
"main": "./dist/cjs/main.js",
"type": "module",
"types": "./dist/main.d.ts",
"exports": "./dist/main.js",
"module": "./dist/esm/main.js",
"exports": {
".": {
"types": "./dist/esm/main.d.ts",
"import": "./dist/esm/main.js",
"require": "./dist/cjs/main.js"
}
},
"engines": {
"node": ">=14.16"
},
Expand All @@ -15,7 +23,7 @@
"scripts": {
"dev": "tsup --watch",
"clean": "rimraf dist",
"build": "tsup",
"build": "tsup && zx ../../scripts/patchCjs.mjs",
"build:test": "tsup --sourcemap inline",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package vite-plugin-checker",
"release": "zx ../../scripts/release.mjs"
Expand Down Expand Up @@ -79,7 +87,7 @@
"esbuild": "^0.14.27",
"npm-run-all": "^4.1.5",
"optionator": "^0.9.1",
"tsup": "^5.12.3",
"tsup": "^6.2.2",
"typescript": "~4.5.5",
"vls": "^0.7.6",
"vti": "^0.1.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import fs from 'fs'
import path from 'path'
import { createRequire } from 'module'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
const _require = createRequire(import.meta.url)

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const proxyPath = _require.resolve('vue-tsc/out/proxy')

const textToReplace: { target: string; replacement: string }[] = [
Expand Down
4 changes: 3 additions & 1 deletion packages/vite-plugin-checker/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const _require = createRequire(import.meta.url)
// #region
// NOTE: sync modification with packages/runtime/src/ws.js
export const RUNTIME_PUBLIC_PATH = '/@vite-plugin-checker-runtime'
export const RUNTIME_FILE_PATH = _require.resolve('../@runtime/main.js')
export const RUNTIME_FILE_PATH = import.meta.url.endsWith('.ts')
? _require.resolve('../@runtime/main.js')
: _require.resolve('../../@runtime/main.js')
export const WS_CHECKER_ERROR_EVENT = 'vite-plugin-checker:error'
export const WS_CHECKER_RECONNECT_EVENT = 'vite-plugin-checker:reconnect'
// #endregion
Expand Down
30 changes: 23 additions & 7 deletions packages/vite-plugin-checker/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { defineConfig } from 'tsup'
import { defineConfig, Options } from 'tsup'

export default defineConfig({
const shared: Options = {
entry: ['src'],
outDir: 'dist',
splitting: false,
bundle: false,
format: ['esm'],
sourcemap: true,
// do not clean @runtime code on watch mode
clean: false,
clean: true,
target: 'node14',
platform: 'node',
dts: true,
})
}

export default defineConfig([
{
format: ['esm'],
outDir: 'dist/esm',
...shared,
},
{
format: ['cjs'],
outDir: 'dist/cjs',
shims: true,
outExtension({ format }) {
return {
js: `.js`,
}
},
...shared,
},
])
2 changes: 1 addition & 1 deletion playground/typescript-react/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"private": true,
"name": "@playground/typescript-react",
"type": "module",
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
Loading

0 comments on commit c39e502

Please sign in to comment.