Skip to content

Commit

Permalink
build NPM package via Vite
Browse files Browse the repository at this point in the history
Also declares React as a peer dependency, addressing Issue GeorgeGkas#3
  • Loading branch information
hfxbse committed Jun 26, 2024
1 parent b52e854 commit d38a1b3
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ npm-debug.log*
/dist
*storybook.log
/storybook-static

# NPM tar balls
*.tgz
11 changes: 0 additions & 11 deletions .npmignore

This file was deleted.

2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
- `npm run build` creates a production build by default.

To create a development build, set the `NODE_ENV` environment variable to `development` while running this command.

- `npm run clean` will delete built resources.
11 changes: 5 additions & 6 deletions package-lock.json

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

24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"name": "super-react-gist",
"version": "1.1.1",
"version": "1.1.2",
"description": "Simple and flexible component that allows you to embed GitHub Gists in React projects.",
"main": "lib/index.js",
"module": "es/index.js",
"files": [
"es",
"lib",
"umd",
"src/index.jsx"
],
"exports": {
".": {
"import": "./es/index.js",
"require": "./lib/index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/georgegkas/super-react-gist.git"
Expand Down Expand Up @@ -35,12 +47,11 @@
],
"license": "MIT",
"dependencies": {
"dompurify": "^2.3.6",
"react": ">=16.14.0",
"react-dom": ">=16.14.0"
"dompurify": "^2.3.6"
},
"peerDependencies": {
"react": ">=16.14.0"
"react": ">=16.14.0",
"react-dom": ">=16.14.0"
},
"devDependencies": {
"@storybook/addon-essentials": "^8.1.10",
Expand All @@ -52,6 +63,7 @@
"vite": "^5.3.1"
},
"scripts": {
"start": "storybook dev -p 3000"
"start": "storybook dev -p 3000",
"build": "vite build"
}
}
1 change: 0 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const Gist = ({
setGistError(true)
setGistIsFetching(false)
onError?.()
return
}

React.useEffect(() => {
Expand Down
39 changes: 39 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import packageDefinition from './package.json' assert {type: 'json'}
import * as fs from "node:fs";
import {resolve} from "path";
import {defineConfig} from "vite";

export default defineConfig({
build: {
outDir: '.',
sourcemap: true,
lib: {
entry: resolve(__dirname, 'src/index.jsx'),
name: 'super-react-gist',
formats: ['cjs', 'umd', 'umd', 'es'],
fileName: (moduleFormat) => {
const directory = {
cjs: 'lib',
umd: 'umd',
es: 'es'
}[moduleFormat]

const fileName = moduleFormat === 'umd' ? packageDefinition.name : 'index'
const filePath = `${directory}/${fileName}.js`

return !fs.existsSync(filePath) ? filePath : `${directory}/${fileName}.min.js`
}
},
rollupOptions: {
external: ['react', 'react-dom'],
output: {
globals: {
gist: 'Gist'
}
},
}
},
resolve: {
dedupe: ['react', 'react-dom'],
},
})

0 comments on commit d38a1b3

Please sign in to comment.