-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[2] GraphiQL x Vite v5 #3679
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
[2] GraphiQL x Vite v5 #3679
Changes from 8 commits
75d59f8
a7082d6
39724c6
9986069
7cad659
85c1939
271e268
ba3f9c3
721afa2
5dd3707
78afcd0
e5277a2
b495ed1
5e16d76
956af89
a22d4ab
c8112fe
30d6e58
34010d5
62656d0
cdcc678
a5d4c70
9180437
5be31b7
47e495e
a9304f1
538938c
80c6811
6d67b9f
a803214
19ac114
5c92320
4b5de1a
0544b30
3ce155c
80bd1fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/test/images/logo.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>GraphiQL</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
|
||
#graphiql { | ||
height: 100dvh; | ||
} | ||
|
||
.loading { | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 4rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="graphiql"> | ||
<div class="loading">Loading…</div> | ||
</div> | ||
<script type="module"> | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import GraphiQL from './src/cdn'; | ||
|
||
Object.assign(globalThis, { | ||
React, | ||
ReactDOM, | ||
GraphiQL, | ||
}); | ||
</script> | ||
<script type="module" src="resources/renderExample.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
module.exports = ({ options, webpackLoaderContext }) => ({ | ||
module.exports = { | ||
plugins: { | ||
// https://github.com/postcss/postcss-import/issues/442#issuecomment-822427606 | ||
'postcss-import': { root: webpackLoaderContext.context }, | ||
// contains autoprefixer, etc | ||
'postcss-preset-env': options['postcss-preset-env'] || false, | ||
cssnano: process.env.NODE_ENV === 'production' ? options.cssnano : false, | ||
'postcss-import': '', | ||
'postcss-lightningcss': { | ||
browsers: '>= .25%', | ||
}, | ||
}, | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/test/images/logo.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>GraphiQL</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
|
||
#graphiql { | ||
height: 100dvh; | ||
} | ||
|
||
.loading { | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 4rem; | ||
} | ||
</style> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react@18/umd/react.development.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" | ||
></script> | ||
<link href="/dist/style.css" rel="stylesheet" /> | ||
<script src="/dist/index.umd.js"></script> | ||
</head> | ||
<body> | ||
<div id="graphiql"> | ||
<div class="loading">Loading…</div> | ||
</div> | ||
<script type="module" src="/resources/renderExample.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { defineConfig } from 'vite'; | ||
import packageJSON from './package.json'; | ||
import dts from 'vite-plugin-dts'; | ||
import commonjs from 'vite-plugin-commonjs'; | ||
|
||
const umdConfig = defineConfig({ | ||
define: { | ||
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`, | ||
}, | ||
// To bundle `const { createClient } = require('graphql-ws')` in `createWebsocketsFetcherFromUrl` function | ||
plugins: [commonjs()], | ||
build: { | ||
minify: true, | ||
dimaMachina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sourcemap: true, | ||
emptyOutDir: false, | ||
lib: { | ||
entry: 'src/cdn.ts', | ||
// 👇 The name of the exposed global variable. Required when the formats option includes umd or iife | ||
name: 'GraphiQL', | ||
fileName: 'index', | ||
formats: ['umd'], | ||
}, | ||
rollupOptions: { | ||
external: ['react', 'react-dom'], | ||
output: { | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const esmConfig = defineConfig({ | ||
build: { | ||
minify: false, | ||
sourcemap: true, | ||
lib: { | ||
entry: 'src/index.ts', | ||
fileName: 'index', | ||
formats: ['cjs', 'es'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need a bundle of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's quite a big step to get rid of cjs, if it doesn't cost you much to keep outputting cjs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with dropping |
||
}, | ||
rollupOptions: { | ||
external: [ | ||
// Exclude peer dependencies and dependencies from bundle | ||
...Object.keys(packageJSON.peerDependencies), | ||
...Object.keys(packageJSON.dependencies), | ||
], | ||
}, | ||
}, | ||
server: { | ||
// prevent browser window from opening automatically | ||
open: false, | ||
proxy: { | ||
'/graphql': 'http://localhost:8080', | ||
'/bad/graphql': 'http://localhost:8080', | ||
'/http-error/graphql': 'http://localhost:8080', | ||
'/graphql-error/graphql': 'http://localhost:8080', | ||
'/subscriptions': { | ||
target: 'ws://localhost:8081', | ||
ws: true, | ||
}, | ||
}, | ||
}, | ||
plugins: [dts({ rollupTypes: true })], | ||
}); | ||
|
||
export default process.env.UMD === 'true' ? umdConfig : esmConfig; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ linenumber | |
linenumbers | ||
linkify | ||
listbox | ||
lightningcss | ||
listvalues | ||
lostplan | ||
maint | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found how to easily get version of
graphql-js
without importingpackage.json
or injecting code