redoc/webpack.config.ts

103 lines
2.5 KiB
TypeScript
Raw Normal View History

2017-11-20 00:26:41 +03:00
import * as webpack from 'webpack';
2017-11-19 23:36:36 +03:00
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
2018-03-17 16:11:52 +03:00
import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import * as path from 'path';
2017-11-20 01:59:28 +03:00
const nodeExternals = require('webpack-node-externals')({
// bundle in moudules that need transpiling + non-js (e.g. css)
2017-12-07 14:52:32 +03:00
whitelist: ['swagger2openapi', /reftools/, /\.(?!(?:jsx?|json)$).{1,5}$/i],
2017-11-20 01:59:28 +03:00
});
2017-10-12 00:01:37 +03:00
const VERSION = JSON.stringify(require('./package.json').version);
const REVISION = JSON.stringify(
require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim(),
);
2018-03-17 18:58:28 +03:00
export default (env: { standalone?: boolean } = {}) => ({
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',
},
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
node: {
fs: 'empty',
},
performance: false,
optimization: {
minimize: !!env.standalone,
},
externals: env.standalone
? {
esprima: 'esprima',
'node-fetch': 'null',
}
: (context, request, callback) => {
// ignore node-fetch dep of swagger2openapi as it is not used
if (/node-fetch$/i.test(request)) return callback(null, 'var undefined');
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?$/,
use: {
loader: 'ts-loader',
options: {
compilerOptions: {
module: 'es2015',
},
},
2017-11-15 00:40:38 +03:00
},
2018-03-17 18:58:28 +03:00
exclude: ['node_modules'],
},
{
test: /node_modules\/(swagger2openapi|reftools)\/.*\.js$/,
use: {
loader: 'ts-loader',
options: {
instance: 'ts2js-transpiler-only',
transpileOnly: true,
compilerOptions: {
allowJs: true,
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: {
sourceMap: true,
minimize: true,
},
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-17 18:58:28 +03:00
],
});