fix: add browser build for webpack 5

This commit is contained in:
Alex Varchuk 2021-11-19 17:14:24 +02:00
parent 262177ddfd
commit d2ae3186b9
3 changed files with 8 additions and 5 deletions

View File

@ -27,6 +27,7 @@
"React.js" "React.js"
], ],
"main": "bundles/redoc.lib.js", "main": "bundles/redoc.lib.js",
"browser": "bundles/redoc.browser.lib.js",
"types": "typings/index.d.ts", "types": "typings/index.d.ts",
"scripts": { "scripts": {
"start": "webpack serve --mode=development --env playground --hot --config demo/webpack.config.ts", "start": "webpack serve --mode=development --env playground --hot --config demo/webpack.config.ts",
@ -42,7 +43,8 @@
"bundle:clean": "rimraf bundles", "bundle:clean": "rimraf bundles",
"bundle:standalone": "webpack --env production --env standalone --mode=production", "bundle:standalone": "webpack --env production --env standalone --mode=production",
"bundle:lib": "webpack --mode=production && npm run declarations", "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/", "declarations": "tsc --emitDeclarationOnly -p tsconfig.lib.json && cp -R src/types typings/",
"stats": "webpack --env production --env standalone --json --profile --mode=production > stats.json", "stats": "webpack --env production --env standalone --json --profile --mode=production > stats.json",
"prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"", "prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"",

1
src/fs.empty.js Normal file
View File

@ -0,0 +1 @@
module.exports = {}

View File

@ -32,10 +32,10 @@ const BANNER = `ReDoc - OpenAPI/Swagger-generated API Reference Documentation
Version: ${VERSION} Version: ${VERSION}
Repo: https://github.com/Redocly/redoc`; 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', entry: env.standalone ? ['./src/polyfills.ts', './src/standalone.tsx'] : './src/index.ts',
output: { 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'), path: path.join(__dirname, '/bundles'),
library: 'Redoc', library: 'Redoc',
libraryTarget: 'umd', libraryTarget: 'umd',
@ -47,13 +47,13 @@ export default (env: { standalone?: boolean } = {}) => ({
fallback: { fallback: {
path: require.resolve('path-browserify'), path: require.resolve('path-browserify'),
http: false, http: false,
fs: false, fs: env.browser ? path.resolve(__dirname, 'src/fs.empty.js') : false,
os: false, os: false,
} }
}, },
performance: false, performance: false,
// target: 'node', // target: 'node',
externalsPresets: env.standalone ? {} : { node: true }, externalsPresets: env.standalone || env.browser ? {} : { node: true },
externals: env.standalone externals: env.standalone
? { ? {
esprima: 'null', esprima: 'null',