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

always bundle package.json#dependencies for UMD for @graphiql/plugin-code-exporter and @graphiql/plugin-explorer #3251

Merged
merged 2 commits into from
Jun 21, 2023
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
6 changes: 6 additions & 0 deletions .changeset/nice-sheep-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphiql/plugin-code-exporter': patch
'@graphiql/plugin-explorer': patch
---

always bundle `package.json#dependencies` for UMD build for `@graphiql/plugin-code-exporter` and `@graphiql/plugin-explorer`
2 changes: 1 addition & 1 deletion packages/graphiql-plugin-code-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"scripts": {
"dev": "vite",
"build": "tsc --emitDeclarationOnly && node resources/copy-types.mjs && vite build",
"build": "tsc --emitDeclarationOnly && node resources/copy-types.mjs && vite build && UMD=true vite build",
"preview": "vite preview"
},
"dependencies": {
Expand Down
9 changes: 6 additions & 3 deletions packages/graphiql-plugin-code-exporter/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import packageJSON from './package.json';

// https://vitejs.dev/config/
const IS_UMD = process.env.UMD === 'true';

export default defineConfig({
plugins: [react({ jsxRuntime: 'classic' })],
build: {
// avoid clean cjs/es builds
emptyOutDir: !IS_UMD,
lib: {
entry: 'src/index.tsx',
fileName: 'index',
name: 'GraphiQLPluginCodeExporter',
formats: ['cjs', 'es', 'umd'],
formats: IS_UMD ? ['umd'] : ['cjs', 'es'],
},
rollupOptions: {
external: [
// Exclude peer dependencies and dependencies from bundle
...Object.keys(packageJSON.peerDependencies),
...Object.keys(packageJSON.dependencies),
...(IS_UMD ? [] : Object.keys(packageJSON.dependencies)),
],
output: {
chunkFileNames: '[name].[format].js',
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-plugin-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"scripts": {
"dev": "vite",
"build": "tsc --emitDeclarationOnly && node resources/copy-types.mjs && vite build",
"build": "tsc --emitDeclarationOnly && node resources/copy-types.mjs && vite build && UMD=true vite build",
"preview": "vite preview"
},
"dependencies": {
Expand Down
9 changes: 6 additions & 3 deletions packages/graphiql-plugin-explorer/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import packageJSON from './package.json';

// https://vitejs.dev/config/
const IS_UMD = process.env.UMD === 'true';

export default defineConfig({
plugins: [react({ jsxRuntime: 'classic' })],
build: {
// avoid clean cjs/es builds
emptyOutDir: !IS_UMD,
lib: {
entry: 'src/index.tsx',
fileName: 'index',
name: 'GraphiQLPluginExplorer',
formats: ['cjs', 'es', 'umd'],
formats: IS_UMD ? ['umd'] : ['cjs', 'es'],
},
rollupOptions: {
external: [
// Exclude peer dependencies and dependencies from bundle
...Object.keys(packageJSON.peerDependencies),
...Object.keys(packageJSON.dependencies),
...(IS_UMD ? [] : Object.keys(packageJSON.dependencies)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻 awesome!

this will make things nice and simple for esm/cjs, and the UMD bundle for CDN implementations

],
output: {
chunkFileNames: '[name].[format].js',
Expand Down