Skip to content

Commit

Permalink
Merge pull request #5 from youthfulhps/enhance/node-polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
youthfulhps authored Jul 10, 2023
2 parents ec35ee6 + 5923d57 commit 79dc2e6
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 52 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"test": "jest"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@types/jest": "^29.4.0",
"@types/node": "^18.14.6",
"@typescript-eslint/eslint-plugin": "^5.54.0",
Expand All @@ -42,5 +44,8 @@
"typescript": "^4.9.3",
"vite": "^4.1.0",
"vite-plugin-dts": "^2.0.2"
},
"dependencies": {
"rollup-plugin-polyfill-node": "^0.12.0"
}
}
117 changes: 104 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 44 additions & 39 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
import path from 'path'
import { defineConfig } from 'vite'
import { pascalCase } from 'change-case'
import vitePluginDts from 'vite-plugin-dts'
import pkg from './package.json'
import path from 'path';
import { defineConfig } from 'vite';
import { pascalCase } from 'change-case';
import vitePluginDts from 'vite-plugin-dts';
import pkg from './package.json';
import nodePolyfills from 'rollup-plugin-polyfill-node';

export default defineConfig(({ mode }) => {
const isDev = getModeFromEnv(mode) === 'development'
const isDev = getModeFromEnv(mode) === 'development';

return {
build: {
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
name: pascalCase(pkg.name.split('/').pop() ?? ''),
fileName: 'lib',
formats: ['cjs', 'es', 'umd'],
},
outDir: 'dist',
sourcemap: isDev,
/**
* @see https://rollupjs.org/configuration-options/#watch
*/
watch: isDev ? {} : null,
},
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
plugins: [
vitePluginDts({
insertTypesEntry: true,
}),
],
}
})
return {
build: {
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
name: pascalCase(pkg.name.split('/').pop() ?? ''),
fileName: 'lib',
formats: ['cjs', 'es', 'umd'],
},
outDir: 'dist',
sourcemap: isDev,
/**
* @see https://rollupjs.org/configuration-options/#watch
*/
watch: isDev ? {} : null,
rollupOptions: {
external: ['fs/promises'],
},
},
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
plugins: [
vitePluginDts({
insertTypesEntry: true,
}),
nodePolyfills(),
],
};
});

function getModeFromEnv(mode: unknown) {
switch (mode) {
case 'development':
return mode
default:
return 'production'
}
switch (mode) {
case 'development':
return mode;
default:
return 'production';
}
}

0 comments on commit 79dc2e6

Please sign in to comment.