Skip to content

Commit

Permalink
Merge pull request #4 from clarkmcc/support-commonjs
Browse files Browse the repository at this point in the history
Support ES and CommonJS builds
  • Loading branch information
clarkmcc authored Jan 15, 2024
2 parents 22cb793 + 98b893d commit 57e2a79
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/npm-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Build Package

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npm run build
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Publish Node.js Package
name: Publish NPM Package

on:
release:
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clarkmcc/ngraph",
"version": "0.1.3",
"version": "0.1.4",
"description": "A blender-style node editor built on xyflow",
"repository": "[email protected]:clarkmcc/ngraph.git",
"author": "Clark McCauley <[email protected]>",
Expand All @@ -9,13 +9,16 @@
"files": [
"dist"
],
"main": "dist/main.jsx",
"main": "dist/cjs/main.jsx",
"exports": {
".": {
"import": "./dist/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/es/index.js"
}
},
"types": "dist/index.d.ts",
"types": "dist/es/index.d.ts",
"sideEffects": [
"**/*.css"
],
Expand All @@ -34,7 +37,7 @@
"build-storybook": "storybook build"
},
"peerDependencies": {
"react": ">= 17 < 2"
"react": ">= 17"
},
"resolutions": {
"jackspeak": "2.1.1"
Expand Down
26 changes: 20 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import { glob } from 'glob'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), libInjectCss(), dts({ include: ['lib'] })],
plugins: [
react(),
libInjectCss(),
dts({ include: ['lib'], outDir: ['dist/types'] }),
],
build: {
ssr: false,
copyPublicDir: false,
lib: {
entry: resolve(__dirname, 'lib/index.ts'),
formats: ['es'],
formats: ['es', 'cjs'],
},
rollupOptions: {
external: ['react', 'react/jsx-runtime'],
Expand All @@ -28,10 +32,20 @@ export default defineConfig({
fileURLToPath(new URL(file, import.meta.url)),
]),
),
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
output: [
{
format: 'es',
entryFileNames: '[name].js',
assetFileNames: 'assets/[name][extname]',
dir: 'dist/es',
},
{
format: 'cjs',
entryFileNames: '[name].js',
assetFileNames: 'assets/[name][extname]',
dir: 'dist/cjs',
},
],
},
},
})

0 comments on commit 57e2a79

Please sign in to comment.