Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standalone build #225

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run build
- run: npm run build:standalone
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ npm install @nilfoundation/ui-kit baseui styletron-engine-atomic styletron-react
yarn add @nilfoundation/ui-kit baseui styletron-engine-atomic styletron-react
```

### CDN

```html
<script src="https://unpkg.com/@nilfoundation/ui-kit/dist/ui-kit.iife.js"></script>
```

Notice, that global `React` variable should be accessible, because it is not included in the standalone bundle.

## Usage

```tsx
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"main": "dist/ui-kit.js",
"module": "dist/ui-kit.mjs",
"unpkg": "dist/ui-kit.iife.js",
"types": "dist/ui-kit.d.ts",
"files": [
"dist"
Expand All @@ -16,6 +17,7 @@
"dev": "vite",
"build": "tsc && vite build",
"bundle-types": "api-extractor run",
"build:standalone": "vite build --mode standalone",
"postbuild": "npm run bundle-types && rm -rf ./dist/.temp",
"preview": "vite preview",
"prettier": "prettier --write 'src/**/**/*.{js,ts,tsx,mdx}'",
Expand Down
61 changes: 45 additions & 16 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,52 @@ const createBanner = () => {
*/`;
}

export default defineConfig({
plugins: [
const packagesIncludeInStandalone = [
/baseui\/*/,
'lightweight-charts',
'@uiw/react-codemirror',
'@uiw/codemirror-themes',
'styletron-standard',
'styletron-react',
'copy-to-clipboard',
'inline-style-expand-shorthand',
'react/jsx-runtime',
];

export default defineConfig(({mode}) => {
const isStandalone = mode === 'standalone';
const plugins = [
react(),
eslint(),
externalizeDeps(),
dts({ staticImport: true, outputDir: './dist/.temp' }),
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs'],
},
rollupOptions: {
output: {
banner: createBanner(),
sourcemap: true,
eslint({include: ['./src/**/*.ts', './src/**/*.tsx']}),
externalizeDeps({except: isStandalone ? packagesIncludeInStandalone : []}),
];

if (!isStandalone) {
plugins.push(
dts({ staticImport: true, outputDir: './dist/.temp' }),
);
}

return ({
plugins: plugins,
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: isStandalone ? ['iife'] : ['es', 'cjs'],
name: 'NilFoundationUIKit',
},
rollupOptions: {
output: {
banner: createBanner(),
sourcemap: true,
globals: isStandalone ? {
react: 'React',
'react-dom': 'ReactDOM',
} : undefined,
},
},
outDir: 'dist',
emptyOutDir: !isStandalone,
},
},
})
});
Loading