2018-05-17 11:40:47 +03:00
|
|
|
/* tslint:disable:no-implicit-dependencies */
|
2018-03-17 16:11:52 +03:00
|
|
|
import * as ForkTsCheckerWebpackPlugin from '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';
|
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)
|
2018-07-19 20:23:46 +03:00
|
|
|
whitelist: [
|
|
|
|
'swagger2openapi',
|
|
|
|
/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(
|
|
|
|
require('child_process')
|
|
|
|
.execSync('git rev-parse --short HEAD')
|
|
|
|
.toString()
|
|
|
|
.trim(),
|
|
|
|
);
|
|
|
|
} 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
|
|
|
|
2018-03-23 17:16:13 +03:00
|
|
|
export default (env: { standalone?: boolean } = {}, { mode }) => ({
|
2018-03-17 18:58:28 +03:00
|
|
|
entry: env.standalone ? ['./src/polyfills.ts', './src/standalone.tsx'] : './src/index.ts',
|
|
|
|
output: {
|
|
|
|
filename: env.standalone ? 'redoc.standalone.js' : 'redoc.lib.js',
|
|
|
|
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: {
|
|
|
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
|
|
|
},
|
|
|
|
|
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
},
|
|
|
|
|
|
|
|
performance: false,
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
minimize: !!env.standalone,
|
|
|
|
},
|
|
|
|
|
|
|
|
externals: env.standalone
|
|
|
|
? {
|
2018-03-22 19:51:16 +03:00
|
|
|
esprima: 'esprima',
|
|
|
|
'node-fetch': 'null',
|
2019-05-10 18:03:28 +03:00
|
|
|
'node-fetch-h2': 'null',
|
|
|
|
yaml: 'null',
|
|
|
|
'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
|
2019-05-10 18:03:28 +03:00
|
|
|
if (/esprima|node-fetch|node-fetch-h2|yaml|safe-json-stringify$/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: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2018-03-23 17:16:13 +03:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
compilerOptions: {
|
|
|
|
module: 'es2015',
|
2018-05-17 11:40:47 +03:00
|
|
|
declaration: false,
|
2018-03-23 17:16:13 +03:00
|
|
|
},
|
2018-03-17 15:17:09 +03:00
|
|
|
},
|
2018-03-17 15:56:45 +03:00
|
|
|
},
|
2018-03-23 17:16:13 +03:00
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2018-08-18 16:21:32 +03:00
|
|
|
generatorOpts: {
|
|
|
|
decoratorsBeforeExport: true,
|
|
|
|
},
|
2018-03-23 17:16:13 +03:00
|
|
|
plugins: [
|
2018-08-18 16:21:32 +03:00
|
|
|
['@babel/plugin-syntax-typescript', { isTSX: true }],
|
2018-05-14 10:38:44 +03:00
|
|
|
['@babel/plugin-syntax-decorators', { legacy: true }],
|
2018-03-23 17:16:13 +03:00
|
|
|
'@babel/plugin-syntax-jsx',
|
|
|
|
[
|
|
|
|
'babel-plugin-styled-components',
|
|
|
|
{
|
|
|
|
minify: true,
|
|
|
|
displayName: mode !== 'production',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-10-18 11:27:28 +03:00
|
|
|
exclude: [/node_modules/],
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
{
|
2018-07-19 20:23:46 +03:00
|
|
|
test: /node_modules\/(swagger2openapi|reftools|oas-resolver|oas-kit-common|oas-schema-walker)\/.*\.js$/,
|
2018-03-17 18:58:28 +03:00
|
|
|
use: {
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
instance: 'ts2js-transpiler-only',
|
|
|
|
transpileOnly: true,
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: true,
|
2018-08-18 16:21:32 +03:00
|
|
|
declaration: false,
|
2017-11-15 00:40:38 +03:00
|
|
|
},
|
|
|
|
},
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: {
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
2018-03-22 19:51:16 +03:00
|
|
|
sourceMap: false,
|
2018-01-09 20:00:17 +03:00
|
|
|
},
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
|
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,
|
|
|
|
}),
|
2018-03-17 19:50:55 +03:00
|
|
|
new ForkTsCheckerWebpackPlugin({ silent: true }),
|
2018-03-22 19:51:16 +03:00
|
|
|
new webpack.BannerPlugin(BANNER),
|
2018-03-26 13:55:50 +03:00
|
|
|
ignore(/js-yaml\/dumper\.js$/),
|
|
|
|
ignore(/json-schema-ref-parser\/lib\/dereference\.js/),
|
2018-05-14 12:57:20 +03:00
|
|
|
env.standalone ? ignore(/^\.\/SearchWorker\.worker$/) : ignore(/$non-existing^/),
|
2018-03-17 18:58:28 +03:00
|
|
|
],
|
|
|
|
});
|
2018-03-26 13:55:50 +03:00
|
|
|
|
|
|
|
function ignore(regexp) {
|
|
|
|
return new webpack.NormalModuleReplacementPlugin(regexp, require.resolve('lodash/noop.js'));
|
|
|
|
}
|