Skip to content

Commit

Permalink
Merge pull request #90 from over-engineer/export-types
Browse files Browse the repository at this point in the history
chore(): #77 export types, interfaces, and enums
  • Loading branch information
horprogs committed Dec 7, 2022
2 parents 81d8398 + 5222fa7 commit 117aa68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"lint-md": "remark . --output",
"semantic-release": "semantic-release",
"dev": "vite --port 3001 --force",
"build:vite": "tsc && vite build",
"build:es": "OUTPUT_FORMAT=es vite build",
"build:umd": "OUTPUT_FORMAT=umd vite build",
"build:vite": "rm -rf ./dist && tsc && yarn run build:umd && yarn run build:es",
"build:types": "tsc --project tsconfig.types.json",
"build": "yarn run build:vite && yarn run build:types",
"lint": "tsc && eslint . --ext .ts",
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1701,3 +1701,4 @@ class JustValidate {
}

export default JustValidate;
export * from './modules/interfaces';
3 changes: 3 additions & 0 deletions src/main.umd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import JustValidate from './main';

export default JustValidate;
32 changes: 27 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { defineConfig } from 'vite';
import path from 'path';
import { resolve } from 'path';

const config = {
es: {
entry: resolve(__dirname, 'src/main.ts'),
fileName: () => 'just-validate.es.js',
},
umd: {
entry: resolve(__dirname, 'src/main.umd.ts'),
fileName: () => 'just-validate.production.min.js',
},
};

const currentConfig = config[process.env.OUTPUT_FORMAT];

if (currentConfig === undefined) {
throw new Error('OUTPUT_FORMAT is not defined or is not valid');
}

export default defineConfig(({ command }) => {
if (command === 'serve') {
Expand All @@ -9,14 +26,19 @@ export default defineConfig(({ command }) => {
// command === 'build'
return {
build: {
outDir: 'dist',
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
...currentConfig,
formats: [process.env.OUTPUT_FORMAT],
name: 'JustValidate',
fileName: (format) =>
`just-validate.${format === 'umd' ? 'production.min' : format}.js`,
},
minify: 'terser',
rollupOptions: {},
rollupOptions: {
output: {
exports: process.env.OUTPUT_FORMAT === 'es' ? 'named' : 'default',
},
},
},
};
}
Expand Down

0 comments on commit 117aa68

Please sign in to comment.