Skip to content

Commit d9879b6

Browse files
committed
remove separate webpack config for demo
1 parent d0265a0 commit d9879b6

File tree

7 files changed

+66
-166
lines changed

7 files changed

+66
-166
lines changed

demo/index.html

+48
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,56 @@
107107
}
108108
}
109109
</style>
110+
<link rel="stylesheet" href="./voyager.css" />
111+
<script src="./voyager.standalone.js"></script>
110112
</head>
111113
<body>
114+
<script type="module">
115+
// FIXME: switch to import
116+
const { renderVoyager, voyagerIntrospectionQuery } = GraphQLVoyager;
117+
const PRESETS = {
118+
'Star Wars': await fetchPreset('swapi'),
119+
Yelp: await fetchPreset('yelp'),
120+
'Shopify Storefront': await fetchPreset('shopify'),
121+
GitHub: await fetchPreset('github'),
122+
};
123+
124+
const defaultPreset = PRESETS['Star Wars'];
125+
126+
const currentUrl = new URL(window.location.href);
127+
const url = currentUrl.searchParams.get('url');
128+
const withCredentials = currentUrl.searchParams.get('withCredentials');
129+
130+
const introspection =
131+
url != null ? fetchIntrospection(url, withCredentials) : defaultPreset;
132+
133+
renderVoyager(document.getElementById('root'), {
134+
introspection,
135+
introspectionPresets: PRESETS,
136+
allowToChangeSchema: true,
137+
hideVoyagerLogo: false,
138+
});
139+
140+
async function fetchPreset(name) {
141+
const response = await fetch(`./presets/${name}_introspection.json`);
142+
return response.json();
143+
}
144+
145+
async function fetchIntrospection(url, withCredentials) {
146+
const response = await fetch(url, {
147+
method: 'post',
148+
headers: {
149+
Accept: 'application/json',
150+
'Content-Type': 'application/json',
151+
},
152+
body: JSON.stringify({ query: voyagerIntrospectionQuery }),
153+
...(withCredentials === 'true'
154+
? { credentials: 'include', mode: 'cors' }
155+
: {}),
156+
});
157+
return response.json();
158+
}
159+
</script>
112160
<main id="root">
113161
<h1 style="text-align: center; color: #5d7e86">Loading...</h1>
114162
</main>

demo/index.ts

-53
This file was deleted.

demo/presets.ts

-14
This file was deleted.

package.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
"preversion": "npm ci --ignore-scripts && npm test",
2020
"changelog": "ts-node scripts/gen-changelog.ts",
2121
"test": "npm run lint && npm run check && npm run testonly && npm run prettier:check && npm run check:spelling",
22-
"start": "npm run build:worker && webpack serve --config=webpack-demo.config.ts --mode=development",
22+
"start": "npm run build:worker && webpack serve --mode=development --env standalone",
2323
"serve": "ts-node ./scripts/serve-directory.ts -p 9090 demo-dist",
2424
"clean:release": "rm -rf middleware",
2525
"clean:worker": "rm -rf worker-dist",
26-
"bundle:standalone": "webpack --config=webpack.config.ts --mode=production --env standalone",
27-
"bundle:lib": "webpack --config=webpack.config.ts --mode=production --env lib",
26+
"bundle:standalone": "webpack --mode=production --env standalone",
27+
"bundle:lib": "webpack --mode=production --env lib",
2828
"bundle": "rm -rf dist && npm run bundle:lib && npm run bundle:standalone",
2929
"compile:middleware": "tsc -d src/middleware/index.ts --outDir middleware --lib ES6,DOM,esnext.asynciterable",
3030
"build:worker": "npm run clean:worker && docker-compose up --abort-on-container-exit --build build-worker",
3131
"build:release": "npm run build:worker && npm run bundle && npm run compile:middleware && npm run declarations",
32-
"build:demo": "npm run build:worker && NODE_ENV=production webpack --config=webpack-demo.config.ts --mode=production",
33-
"stats": "NODE_ENV=production webpack --json --config=webpack.config.ts --mode=production > stats.json",
32+
"build:demo": "npm run build:release && rm -rf demo-dist && cp -R demo/ demo-dist/ && cp dist/voyager.css* dist/voyager.standalone.js* demo-dist/",
33+
"stats": "NODE_ENV=production webpack --json --mode=production > stats.json",
3434
"lint": "eslint --cache --max-warnings 0 .",
3535
"check": "tsc",
3636
"prettier": "prettier --cache --write --list-different . **/*.svg",
@@ -64,7 +64,6 @@
6464
"@types/react-dom": "18.0.10",
6565
"@typescript-eslint/eslint-plugin": "5.30.7",
6666
"@typescript-eslint/parser": "5.30.7",
67-
"copy-webpack-plugin": "11.0.0",
6867
"cspell": "6.2.3",
6968
"css-loader": "6.7.1",
7069
"eslint": "8.20.0",
@@ -74,7 +73,6 @@
7473
"eslint-plugin-react-hooks": "4.6.0",
7574
"eslint-plugin-simple-import-sort": "10.0.0",
7675
"graphql": "16.5.0",
77-
"html-webpack-plugin": "5.5.0",
7876
"mini-css-extract-plugin": "2.6.0",
7977
"postcss-cssnext": "3.1.1",
8078
"postcss-import": "12.0.1",

tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
"./src/**/*.ts",
2222
"./src/**/*.tsx",
2323
"./manual-types.d.ts",
24-
"demo/**/*.ts",
2524
"tests/**/*.ts",
2625
"scripts/**/*.ts",
2726
"playwright.config.ts",
28-
"webpack.config.ts",
29-
"webpack-demo.config.ts"
27+
"webpack.config.ts"
3028
],
3129
"ts-node": {
3230
"compilerOptions": {

webpack-demo.config.ts

-88
This file was deleted.

webpack.config.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ interface Env {
1515
standalone?: boolean;
1616
}
1717

18-
export default function buildWebpackConfig(env: Env): webpack.Configuration {
18+
// FIXME: switch any to webpack.Configuration
19+
export default function buildWebpackConfig(env: Env): any {
1920
if (env.lib === true) {
2021
return {
2122
...baseConfig,
@@ -34,9 +35,19 @@ export default function buildWebpackConfig(env: Env): webpack.Configuration {
3435
entry: './src/standalone.ts',
3536
optimization: { minimize: true },
3637
externals: undefined,
38+
devtool: 'source-map',
3739
output: {
3840
...baseConfig.output,
3941
filename: 'voyager.standalone.js',
42+
sourceMapFilename: '[file].map',
43+
},
44+
devServer: {
45+
https: true,
46+
port: 9090,
47+
static: {
48+
directory: path.join(__dirname, 'demo'),
49+
},
50+
liveReload: true,
4051
},
4152
};
4253
}

0 commit comments

Comments
 (0)