Skip to content

Commit

Permalink
feat: include browser bundle for JIT CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jan 25, 2022
1 parent 26a9046 commit d866a51
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .pnp.cjs

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

Binary file not shown.
28 changes: 22 additions & 6 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { BuildOptions } from 'esbuild';
import { build as esBuild } from 'esbuild';
import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';

import {
closeSync,
copyFileSync,
Expand All @@ -15,15 +18,21 @@ const copyFiles = (src: string, dest = src): void => {
src.split(' ').forEach((file, i) => copyFileSync(file, join(__dirname, 'dist', destList[i])));
};

void esBuild({
const opts: BuildOptions = {
bundle: true,
charset: 'utf8',
entryPoints: ['dist/index.js'],
external: ['lodash*', 'tailwindcss'],
minify: true,
outfile: 'dist/index.min.js',
platform: 'node',
plugins: [pnpPlugin()],
target: 'es2019',
};

esBuild({
...opts,
external: ['lodash*', 'tailwindcss'],
platform: 'node',

entryPoints: ['dist/index.js'],
outfile: 'dist/index.min.js',
})
.then(() => {
readdirSync(join(__dirname, 'dist')).forEach((file) => {
Expand All @@ -39,7 +48,14 @@ void esBuild({
writeSync(fd, `${readFileSync(join(__dirname, 'types', 'base.d.ts'))}\n${data}`);
closeSync(fd);

//
// build for browser
return esBuild({
...opts,
format: 'esm',

entryPoints: ['dist/index.min.js'],
outfile: 'dist/bundle.min.js',
});
})
.catch((err) => {
console.error(err);
Expand Down
1 change: 1 addition & 0 deletions package-dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"email": "[email protected]"
},
"main": "index.min.js",
"browser": "bundle.min.js",
"files": [
"index.d.ts"
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/node": "latest",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"@yarnpkg/esbuild-plugin-pnp": "latest",
"@yarnpkg/sdks": "latest",
"autoprefixer": "latest",
"conventional-changelog-conventionalcommits": "latest",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,17 @@ __metadata:
languageName: node
linkType: hard

"@yarnpkg/esbuild-plugin-pnp@npm:latest":
version: 2.0.1-rc.1
resolution: "@yarnpkg/esbuild-plugin-pnp@npm:2.0.1-rc.1"
dependencies:
tslib: ^1.13.0
peerDependencies:
esbuild: ">=0.10.0"
checksum: 05717a9c1c17b71beee3e89dc6caf3b3ffd7db7f2b3f59ed35a5318a7cb2ca3eb2364ef801070919a278bfe43e6ed2df3363f838e3033b552fbf668c57b96bbc
languageName: node
linkType: hard

"@yarnpkg/fslib@npm:^2.5.0":
version: 2.6.0
resolution: "@yarnpkg/fslib@npm:2.6.0"
Expand Down Expand Up @@ -7760,6 +7771,7 @@ __metadata:
"@types/node": latest
"@typescript-eslint/eslint-plugin": latest
"@typescript-eslint/parser": latest
"@yarnpkg/esbuild-plugin-pnp": latest
"@yarnpkg/sdks": latest
autoprefixer: latest
conventional-changelog-conventionalcommits: latest
Expand Down

0 comments on commit d866a51

Please sign in to comment.