2017-10-12 00:01:37 +03:00
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const DashboardPlugin = require('webpack-dashboard/plugin');
|
|
|
|
|
|
|
|
module.exports = env => {
|
|
|
|
env = env || {};
|
|
|
|
|
2017-11-19 13:51:59 +03:00
|
|
|
let entry;
|
|
|
|
if (env.standalone) {
|
|
|
|
entry = ['./src/polyfills.ts', './src/standalone.tsx'];
|
|
|
|
} else {
|
|
|
|
entry = env.prod
|
2017-10-12 00:01:37 +03:00
|
|
|
? env.perf ? ['./perf/index.tsx'] : ['./src/hmr-playground.tsx']
|
|
|
|
: [
|
|
|
|
'react-dev-utils/webpackHotDevClient',
|
|
|
|
'react-hot-loader/patch',
|
|
|
|
'./src/hmr-playground.tsx',
|
2017-11-19 13:51:59 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
entry: entry,
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
output: {
|
2017-11-19 13:51:59 +03:00
|
|
|
filename: env.standalone ? 'redoc.standalone.js' : 'redoc.bundle.js',
|
|
|
|
path: __dirname + '/bundles',
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
contentBase: __dirname + '/demo',
|
|
|
|
watchContentBase: true,
|
|
|
|
port: 9090,
|
|
|
|
stats: 'errors-only',
|
|
|
|
},
|
|
|
|
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
|
|
|
},
|
|
|
|
|
2017-11-15 00:40:38 +03:00
|
|
|
node: {
|
|
|
|
fs: 'empty',
|
|
|
|
},
|
|
|
|
|
2017-10-12 00:01:37 +03:00
|
|
|
externals: {
|
|
|
|
esprima: 'esprima',
|
2017-11-15 00:40:38 +03:00
|
|
|
'node-fetch': 'fetch',
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loaders: ['react-hot-loader/webpack', 'awesome-typescript-loader'],
|
2017-11-15 00:40:38 +03:00
|
|
|
exclude: ['node_modules'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /node_modules\/(swagger2openapi|reftools)\/.*\.js$/,
|
|
|
|
use: {
|
|
|
|
loader: 'awesome-typescript-loader',
|
|
|
|
options: {
|
|
|
|
transpileOnly: true,
|
|
|
|
allowJs: true,
|
|
|
|
instance: 'ts2js-transpiler-only',
|
|
|
|
},
|
|
|
|
},
|
2017-10-12 00:01:37 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
sourceMap: true,
|
|
|
|
minimize: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
},
|
2017-11-15 17:33:02 +03:00
|
|
|
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
|
2017-10-12 00:01:37 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': env.prod ? '"production"' : '"development"',
|
|
|
|
__DEV__: env.prod ? 'false' : 'true',
|
|
|
|
}),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
filename: 'redoc.css',
|
|
|
|
allChunks: true,
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: './demo/index.html',
|
|
|
|
}),
|
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
if (env.prod) {
|
|
|
|
config.plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
|
2017-11-14 18:51:56 +03:00
|
|
|
} else {
|
|
|
|
config.plugins.push(new DashboardPlugin());
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
return config;
|
|
|
|
};
|