diff --git a/package.json b/package.json index 409f480..caddb29 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,10 @@ "format:check": "prettier --check .", "lint": "eslint src/**/*.ts", "lint:fix": "npm run lint -- --fix", - "build": "vite build && esbuild $(find ./src -name \"*.ts\" -type f -not -path '*worker/index.ts' -not -path '*.spec.ts') --outdir=./dist --platform=neutral --format=esm --sourcemap", + "build": "npm run build:worker && npm run build:node && npm run build:browser", + "build:browser": "esbuild $(find ./src -name \"*.ts\" -type f -not -path '*worker/index.ts' -not -path '*.spec.ts') --outdir=./dist --platform=neutral --format=esm --sourcemap", + "build:node": "vite build --config vite.node-config.js", + "build:worker": "vite build --config vite.worker-config.js", "prepublishOnly": "npm run typecheck && npm test && npm run build", "typecheck": "tsc --noEmit" }, diff --git a/src-node/index.ts b/src-node/index.ts index 019bf76..4a083d3 100644 --- a/src-node/index.ts +++ b/src-node/index.ts @@ -1,6 +1,6 @@ -// @ts-nocheck -import './polyfills'; -import { enableFallbackWithoutWorker } from '../src'; -export * from '../src/index'; +import './polyfills.js'; +import { enableFallbackWithoutWorker } from '../src/index.js'; + +export * from '../src/index.js'; enableFallbackWithoutWorker(); diff --git a/src-node/polyfills.ts b/src-node/polyfills.ts index ed9ddc5..b342602 100644 --- a/src-node/polyfills.ts +++ b/src-node/polyfills.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck import 'regenerator-runtime/runtime'; import { EventEmitter } from 'events'; diff --git a/vite.node-config.js b/vite.node-config.js new file mode 100644 index 0000000..b7755b8 --- /dev/null +++ b/vite.node-config.js @@ -0,0 +1,22 @@ +import { defineConfig } from 'vite'; +import { dependencies, devDependencies } from './package.json'; + +export default defineConfig({ + build: { + ssr: true, + rollupOptions: { + external: [/^ol/, 'proj4'], + input: 'src-node/index.ts', + output: { + entryFileNames: 'dist-node.js', + globals: (name) => name, + }, + }, + outDir: 'dist', + minify: false, + }, + ssr: { + noExternal: Object.keys(dependencies).concat(Object.keys(devDependencies)), + target: 'node', + }, +}); diff --git a/vite.config.js b/vite.worker-config.js similarity index 100% rename from vite.config.js rename to vite.worker-config.js