2018-03-23 17:16:13 +03:00
|
|
|
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
|
2020-07-25 19:06:22 +03:00
|
|
|
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2018-07-17 12:15:22 +03:00
|
|
|
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
import { resolve } from 'path';
|
|
|
|
import * as webpack from 'webpack';
|
2021-06-09 14:57:36 +03:00
|
|
|
import { getBabelLoader, webpackIgnore } from '../config/webpack-utils';
|
2018-03-13 13:58:22 +03:00
|
|
|
|
|
|
|
const VERSION = JSON.stringify(require('../package.json').version);
|
|
|
|
const REVISION = JSON.stringify(
|
2020-07-25 19:06:22 +03:00
|
|
|
require('child_process').execSync('git rev-parse --short HEAD').toString().trim(),
|
2018-03-13 13:58:22 +03:00
|
|
|
);
|
|
|
|
|
2018-03-17 18:58:28 +03:00
|
|
|
function root(filename) {
|
|
|
|
return resolve(__dirname + '/' + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) => ({
|
|
|
|
entry: [
|
|
|
|
root('../src/polyfills.ts'),
|
|
|
|
root(
|
|
|
|
env.playground
|
|
|
|
? 'playground/hmr-playground.tsx'
|
2018-07-17 12:15:22 +03:00
|
|
|
: env.bench
|
2019-03-11 18:10:29 +03:00
|
|
|
? '../benchmark/index.tsx'
|
|
|
|
: 'index.tsx',
|
2018-03-17 18:58:28 +03:00
|
|
|
),
|
|
|
|
],
|
2021-06-09 14:57:36 +03:00
|
|
|
target: 'web',
|
2018-03-13 13:58:22 +03:00
|
|
|
output: {
|
|
|
|
filename: 'redoc-demo.bundle.js',
|
2018-03-17 18:58:28 +03:00
|
|
|
path: root('dist'),
|
|
|
|
globalObject: 'this',
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
contentBase: __dirname,
|
|
|
|
watchContentBase: true,
|
2018-03-17 18:58:28 +03:00
|
|
|
port: 9090,
|
|
|
|
disableHostCheck: true,
|
|
|
|
stats: 'minimal',
|
2021-06-09 14:57:36 +03:00
|
|
|
hot: true,
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
2021-06-09 14:57:36 +03:00
|
|
|
fallback: {
|
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
http: false,
|
|
|
|
fs: false,
|
|
|
|
os: false,
|
|
|
|
},
|
2019-03-11 18:08:29 +03:00
|
|
|
alias:
|
|
|
|
mode !== 'production'
|
|
|
|
? {
|
2021-06-09 14:57:36 +03:00
|
|
|
'react-dom': '@hot-loader/react-dom',
|
|
|
|
}
|
2019-03-11 18:08:29 +03:00
|
|
|
: {},
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
2018-03-17 16:11:52 +03:00
|
|
|
|
2018-03-17 18:58:28 +03:00
|
|
|
performance: false,
|
|
|
|
|
2018-03-26 13:55:50 +03:00
|
|
|
externals: {
|
|
|
|
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-26 13:55:50 +03:00
|
|
|
},
|
|
|
|
|
2018-03-13 13:58:22 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{ test: [/\.eot$/, /\.gif$/, /\.woff$/, /\.svg$/, /\.ttf$/], use: 'null-loader' },
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2021-06-09 14:57:36 +03:00
|
|
|
use: [getBabelLoader({useBuiltIns: true, hot: true} )],
|
|
|
|
exclude: {
|
|
|
|
and: [/node_modules/],
|
|
|
|
not: {
|
|
|
|
or: [
|
|
|
|
/swagger2openapi/,
|
|
|
|
/reftools/,
|
|
|
|
/openapi-sampler/,
|
|
|
|
/mobx/,
|
|
|
|
/oas-resolver/,
|
|
|
|
/oas-kit-common/,
|
|
|
|
/oas-schema-walker/,
|
|
|
|
/\@redocly\/openapi-core/,
|
|
|
|
/colorette/,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: {
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
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-13 13:58:22 +03:00
|
|
|
}),
|
2021-06-09 14:57:36 +03:00
|
|
|
// new webpack.NamedModulesPlugin(),
|
|
|
|
// new webpack.optimize.ModuleConcatenationPlugin(),
|
2018-03-13 13:58:22 +03:00
|
|
|
new HtmlWebpackPlugin({
|
2018-10-18 10:40:26 +03:00
|
|
|
template: env.playground
|
|
|
|
? 'demo/playground/index.html'
|
|
|
|
: env.bench
|
2019-03-11 18:10:29 +03:00
|
|
|
? 'benchmark/index.html'
|
|
|
|
: 'demo/index.html',
|
2018-03-13 13:58:22 +03:00
|
|
|
}),
|
2021-06-09 14:57:36 +03:00
|
|
|
new ForkTsCheckerWebpackPlugin({ logger: { infrastructure: 'silent', issues: 'console' } }),
|
|
|
|
webpackIgnore(/js-yaml\/dumper\.js$/),
|
|
|
|
webpackIgnore(/json-schema-ref-parser\/lib\/dereference\.js/),
|
|
|
|
webpackIgnore(/^\.\/SearchWorker\.worker$/),
|
2020-07-25 19:06:22 +03:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: ['demo/openapi.yaml'],
|
|
|
|
}),
|
2018-03-13 13:58:22 +03:00
|
|
|
],
|
2018-03-17 18:58:28 +03:00
|
|
|
});
|