2018-05-17 11:40:47 +03:00
|
|
|
/* tslint:disable:no-implicit-dependencies */
|
2020-07-25 19:06:22 +03:00
|
|
|
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2018-05-17 11:40:47 +03:00
|
|
|
import * as webpack from 'webpack';
|
2018-03-17 16:11:52 +03:00
|
|
|
import * as path from 'path';
|
2022-01-25 16:50:28 +03:00
|
|
|
import { webpackIgnore } from './config/webpack-utils';
|
2017-11-20 01:59:28 +03:00
|
|
|
|
|
|
|
const nodeExternals = require('webpack-node-externals')({
|
2019-12-10 09:13:37 +03:00
|
|
|
// bundle in modules that need transpiling + non-js (e.g. css)
|
2020-07-25 19:06:22 +03:00
|
|
|
allowlist: [
|
2018-07-19 20:23:46 +03:00
|
|
|
'swagger2openapi',
|
2022-05-10 14:50:50 +03:00
|
|
|
'marked',
|
2018-07-19 20:23:46 +03:00
|
|
|
/reftools/,
|
|
|
|
'oas-resolver',
|
|
|
|
'oas-kit-common',
|
|
|
|
'oas-schema-walker',
|
|
|
|
/\.(?!(?:jsx?|json)$).{1,5}$/i,
|
|
|
|
],
|
2017-11-20 01:59:28 +03:00
|
|
|
});
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2017-11-22 14:02:15 +03:00
|
|
|
const VERSION = JSON.stringify(require('./package.json').version);
|
2018-11-06 16:24:12 +03:00
|
|
|
let REVISION;
|
|
|
|
|
|
|
|
try {
|
|
|
|
REVISION = JSON.stringify(
|
2020-07-25 19:06:22 +03:00
|
|
|
require('child_process').execSync('git rev-parse --short HEAD').toString().trim(),
|
2018-11-06 16:24:12 +03:00
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Skipping REDOC_REVISION');
|
|
|
|
}
|
2017-11-22 14:02:15 +03:00
|
|
|
|
2018-03-22 19:51:16 +03:00
|
|
|
const BANNER = `ReDoc - OpenAPI/Swagger-generated API Reference Documentation
|
2018-03-21 21:08:46 +03:00
|
|
|
-------------------------------------------------------------
|
|
|
|
Version: ${VERSION}
|
2019-06-04 15:47:22 +03:00
|
|
|
Repo: https://github.com/Redocly/redoc`;
|
2018-03-21 21:08:46 +03:00
|
|
|
|
2022-01-05 18:11:05 +03:00
|
|
|
export default (env: { standalone?: boolean; browser?: boolean } = {}) => ({
|
2018-03-17 18:58:28 +03:00
|
|
|
entry: env.standalone ? ['./src/polyfills.ts', './src/standalone.tsx'] : './src/index.ts',
|
|
|
|
output: {
|
2022-01-05 18:11:05 +03:00
|
|
|
filename: env.standalone
|
|
|
|
? 'redoc.standalone.js'
|
|
|
|
: env.browser
|
|
|
|
? 'redoc.browser.lib.js'
|
|
|
|
: 'redoc.lib.js',
|
2018-03-17 18:58:28 +03:00
|
|
|
path: path.join(__dirname, '/bundles'),
|
|
|
|
library: 'Redoc',
|
|
|
|
libraryTarget: 'umd',
|
2018-03-18 12:15:17 +03:00
|
|
|
globalObject: 'this',
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
devtool: 'source-map',
|
|
|
|
resolve: {
|
2021-06-09 14:57:36 +03:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.mjs', '.json'],
|
|
|
|
fallback: {
|
|
|
|
path: require.resolve('path-browserify'),
|
2022-01-25 16:50:28 +03:00
|
|
|
buffer: require.resolve('buffer'),
|
2021-06-09 14:57:36 +03:00
|
|
|
http: false,
|
2021-11-29 15:27:06 +03:00
|
|
|
fs: path.resolve(__dirname, 'src/empty.js'),
|
|
|
|
os: path.resolve(__dirname, 'src/empty.js'),
|
|
|
|
tty: path.resolve(__dirname, 'src/empty.js'),
|
2022-01-05 18:11:05 +03:00
|
|
|
},
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
performance: false,
|
2021-11-29 15:27:06 +03:00
|
|
|
externalsPresets: env.standalone || env.browser ? {} : { node: true },
|
2018-03-17 18:58:28 +03:00
|
|
|
externals: env.standalone
|
|
|
|
? {
|
2021-06-09 14:57:36 +03:00
|
|
|
esprima: 'null',
|
2018-03-22 19:51:16 +03:00
|
|
|
'node-fetch': 'null',
|
2019-05-10 18:03:28 +03:00
|
|
|
'node-fetch-h2': 'null',
|
|
|
|
yaml: 'null',
|
2022-05-10 14:50:50 +03:00
|
|
|
url: 'null',
|
2019-05-10 18:03:28 +03:00
|
|
|
'safe-json-stringify': 'null',
|
2018-03-22 19:51:16 +03:00
|
|
|
}
|
2018-03-17 18:58:28 +03:00
|
|
|
: (context, request, callback) => {
|
2018-03-22 19:51:16 +03:00
|
|
|
// ignore node-fetch dep of swagger2openapi as it is not used
|
2022-05-10 14:50:50 +03:00
|
|
|
if (/esprima|node-fetch|node-fetch-h2|\/yaml|safe-json-stringify|url$/i.test(request)) {
|
2018-05-17 11:40:47 +03:00
|
|
|
return callback(null, 'var undefined');
|
|
|
|
}
|
2018-03-22 19:51:16 +03:00
|
|
|
return nodeExternals(context, request, callback);
|
|
|
|
},
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-03-17 18:58:28 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-06-09 14:57:36 +03:00
|
|
|
test: /\.(tsx?|[cm]?js)$/,
|
2022-01-25 16:50:28 +03:00
|
|
|
loader: 'esbuild-loader',
|
|
|
|
options: {
|
|
|
|
loader: 'tsx',
|
|
|
|
target: 'es2015',
|
|
|
|
tsconfigRaw: require('./tsconfig.json'),
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
2022-01-25 16:50:28 +03:00
|
|
|
exclude: [/node_modules/],
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2022-01-25 16:50:28 +03:00
|
|
|
use: [
|
2022-01-27 14:46:05 +03:00
|
|
|
'style-loader',
|
2022-01-25 16:50:28 +03:00
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'esbuild-loader',
|
|
|
|
options: {
|
|
|
|
loader: 'css',
|
|
|
|
minify: true,
|
|
|
|
},
|
2018-01-09 20:00:17 +03:00
|
|
|
},
|
2022-01-25 16:50:28 +03:00
|
|
|
],
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
2017-10-12 00:01:37 +03:00
|
|
|
],
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__REDOC_VERSION__: VERSION,
|
|
|
|
__REDOC_REVISION__: REVISION,
|
2021-06-09 14:57:36 +03:00
|
|
|
'process.env': '{}',
|
|
|
|
'process.platform': '"browser"',
|
|
|
|
'process.stdout': 'null',
|
2018-03-17 18:58:28 +03:00
|
|
|
}),
|
2020-07-25 19:06:22 +03:00
|
|
|
new ForkTsCheckerWebpackPlugin({ logger: { infrastructure: 'silent', issues: 'console' } }),
|
2018-03-22 19:51:16 +03:00
|
|
|
new webpack.BannerPlugin(BANNER),
|
2022-01-25 16:50:28 +03:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
|
|
|
}),
|
2021-06-09 14:57:36 +03:00
|
|
|
webpackIgnore(/js-yaml\/dumper\.js$/),
|
|
|
|
env.standalone ? webpackIgnore(/^\.\/SearchWorker\.worker$/) : undefined,
|
|
|
|
].filter(Boolean),
|
2018-03-17 18:58:28 +03:00
|
|
|
});
|