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

fix: add browser build for webpack 5 #1796

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"React.js"
],
"main": "bundles/redoc.lib.js",
"browser": "bundles/redoc.browser.lib.js",
"types": "typings/index.d.ts",
"scripts": {
"start": "webpack serve --mode=development --env playground --hot --config demo/webpack.config.ts",
Expand All @@ -42,7 +43,8 @@
"bundle:clean": "rimraf bundles",
"bundle:standalone": "webpack --env production --env standalone --mode=production",
"bundle:lib": "webpack --mode=production && npm run declarations",
"bundle": "npm run bundle:clean && npm run bundle:lib && npm run bundle:standalone",
"bundle:browser": "webpack --env production --env browser --mode=production",
"bundle": "npm run bundle:clean && npm run bundle:lib && npm run bundle:browser && npm run bundle:standalone",
"declarations": "tsc --emitDeclarationOnly -p tsconfig.lib.json && cp -R src/types typings/",
"stats": "webpack --env production --env standalone --json --profile --mode=production > stats.json",
"prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"",
Expand Down
7 changes: 0 additions & 7 deletions src/services/SearchWorker.worker.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import * as lunr from 'lunr';

try {
// tslint:disable-next-line
require('core-js/es/promise'); // bundle into worker
} catch (_) {
// nope
}

/* just for better typings */
export default class Worker {
add: typeof add = add;
Expand Down
12 changes: 6 additions & 6 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const BANNER = `ReDoc - OpenAPI/Swagger-generated API Reference Documentation
Version: ${VERSION}
Repo: https://github.com/Redocly/redoc`;

export default (env: { standalone?: boolean } = {}) => ({
export default (env: { standalone?: boolean, browser?: boolean } = {}) => ({
entry: env.standalone ? ['./src/polyfills.ts', './src/standalone.tsx'] : './src/index.ts',
output: {
filename: env.standalone ? 'redoc.standalone.js' : 'redoc.lib.js',
filename: env.standalone ? 'redoc.standalone.js' : env.browser ? 'redoc.browser.lib.js' : 'redoc.lib.js',
path: path.join(__dirname, '/bundles'),
library: 'Redoc',
libraryTarget: 'umd',
Expand All @@ -47,13 +47,13 @@ export default (env: { standalone?: boolean } = {}) => ({
fallback: {
path: require.resolve('path-browserify'),
http: false,
fs: false,
os: false,
fs: env.browser ? path.resolve(__dirname, 'src/empty.js') : false,
Copy link
Member

Choose a reason for hiding this comment

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

I believe we don't need this conditional here, just keep it empty. It will be overwritten by externalsPresets anyways.

os: path.resolve(__dirname, 'src/empty.js'),
tty: path.resolve(__dirname, 'src/empty.js'),
}
},
performance: false,
// target: 'node',
externalsPresets: env.standalone ? {} : { node: true },
externalsPresets: env.standalone || env.browser ? {} : { node: true },
externals: env.standalone
? {
esprima: 'null',
Expand Down