From d2ae3186b9256a555383f029c23c5e05f444c701 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Fri, 19 Nov 2021 17:14:24 +0200 Subject: [PATCH] fix: add browser build for webpack 5 --- package.json | 4 +++- src/fs.empty.js | 1 + webpack.config.ts | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 src/fs.empty.js diff --git a/package.json b/package.json index 905992a1..b087b447 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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:standalone && npm run bundle:browser", "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}\"", diff --git a/src/fs.empty.js b/src/fs.empty.js new file mode 100644 index 00000000..7c6d6c73 --- /dev/null +++ b/src/fs.empty.js @@ -0,0 +1 @@ +module.exports = {} \ No newline at end of file diff --git a/webpack.config.ts b/webpack.config.ts index dee1ada4..0d5ecf8f 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -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', @@ -47,13 +47,13 @@ export default (env: { standalone?: boolean } = {}) => ({ fallback: { path: require.resolve('path-browserify'), http: false, - fs: false, + fs: env.browser ? path.resolve(__dirname, 'src/fs.empty.js') : false, os: false, } }, performance: false, // target: 'node', - externalsPresets: env.standalone ? {} : { node: true }, + externalsPresets: env.standalone || env.browser ? {} : { node: true }, externals: env.standalone ? { esprima: 'null',