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';
|
2018-03-23 17:16:13 +03:00
|
|
|
import { compact } from 'lodash';
|
2018-07-17 12:15:22 +03:00
|
|
|
import { resolve } from 'path';
|
|
|
|
import * as webpack from 'webpack';
|
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);
|
|
|
|
}
|
|
|
|
|
2020-07-25 19:06:22 +03:00
|
|
|
const tsLoader = (env) => ({
|
2018-03-17 18:58:28 +03:00
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
compilerOptions: {
|
|
|
|
module: env.bench ? 'esnext' : 'es2015',
|
2018-09-19 10:08:24 +03:00
|
|
|
declaration: false,
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-25 19:06:22 +03:00
|
|
|
const babelLoader = (mode) => ({
|
2018-03-17 18:58:28 +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: compact([
|
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-10-18 10:40:26 +03:00
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
2018-03-17 18:58:28 +03:00
|
|
|
'@babel/plugin-syntax-jsx',
|
2018-03-23 17:16:13 +03:00
|
|
|
[
|
|
|
|
'babel-plugin-styled-components',
|
|
|
|
{
|
|
|
|
minify: true,
|
|
|
|
displayName: mode !== 'production',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]),
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
2018-03-23 17:16:13 +03:00
|
|
|
});
|
2018-03-17 18:58:28 +03:00
|
|
|
|
2019-07-29 18:41:57 +03:00
|
|
|
const babelHotLoader = {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
plugins: ['react-hot-loader/babel'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:58:28 +03:00
|
|
|
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
|
|
|
),
|
|
|
|
],
|
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',
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
2019-03-11 18:08:29 +03:00
|
|
|
alias:
|
|
|
|
mode !== 'production'
|
|
|
|
? {
|
|
|
|
'react-dom': '@hot-loader/react-dom',
|
|
|
|
}
|
|
|
|
: {},
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
2018-03-17 16:11:52 +03:00
|
|
|
|
2018-03-14 09:05:57 +03:00
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
},
|
2018-03-13 13:58:22 +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: [
|
|
|
|
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
|
|
|
|
{ test: [/\.eot$/, /\.gif$/, /\.woff$/, /\.svg$/, /\.ttf$/], use: 'null-loader' },
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2019-07-29 18:41:57 +03:00
|
|
|
use: compact([
|
|
|
|
mode !== 'production' ? babelHotLoader : undefined,
|
|
|
|
tsLoader(env),
|
|
|
|
babelLoader(mode),
|
|
|
|
]),
|
2018-10-18 11:27:28 +03:00
|
|
|
exclude: [/node_modules/],
|
2018-03-13 13:58:22 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: {
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-14 09:05:57 +03:00
|
|
|
{
|
2018-09-19 09:59:11 +03:00
|
|
|
test: /node_modules\/(swagger2openapi|reftools|oas-resolver|oas-kit-common|oas-schema-walker)\/.*\.js$/,
|
2018-03-14 09:05:57 +03:00
|
|
|
use: {
|
2018-03-17 16:11:52 +03:00
|
|
|
loader: 'ts-loader',
|
2018-03-14 09:05:57 +03:00
|
|
|
options: {
|
2018-03-17 18:58:28 +03:00
|
|
|
transpileOnly: true,
|
|
|
|
instance: 'ts2js-transpiler-only',
|
|
|
|
compilerOptions: {
|
|
|
|
allowJs: true,
|
2018-08-18 16:21:32 +03:00
|
|
|
declaration: false,
|
2018-03-17 18:58:28 +03:00
|
|
|
},
|
2018-03-14 09:05:57 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-03-13 13:58:22 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__REDOC_VERSION__: VERSION,
|
|
|
|
__REDOC_REVISION__: REVISION,
|
|
|
|
}),
|
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
|
|
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
|
|
|
}),
|
2018-03-17 18:58:28 +03:00
|
|
|
new ForkTsCheckerWebpackPlugin(),
|
2018-03-26 13:55:50 +03:00
|
|
|
ignore(/js-yaml\/dumper\.js$/),
|
|
|
|
ignore(/json-schema-ref-parser\/lib\/dereference\.js/),
|
2018-03-26 18:17:01 +03:00
|
|
|
ignore(/^\.\/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
|
|
|
});
|
2018-03-26 13:55:50 +03:00
|
|
|
|
|
|
|
function ignore(regexp) {
|
|
|
|
return new webpack.NormalModuleReplacementPlugin(regexp, require.resolve('lodash/noop.js'));
|
|
|
|
}
|