redoc/demo/webpack.config.ts

119 lines
2.7 KiB
TypeScript
Raw Normal View History

2018-03-13 13:58:22 +03:00
import * as webpack from 'webpack';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
2018-03-17 18:58:28 +03:00
import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import { resolve } from 'path';
2018-03-13 13:58:22 +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
function root(filename) {
return resolve(__dirname + '/' + filename);
}
const tsLoader = env => ({
loader: 'ts-loader',
options: {
compilerOptions: {
module: env.bench ? 'esnext' : 'es2015',
},
},
});
const babelHotLoader = {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-syntax-typescript',
'@babel/plugin-syntax-decorators',
'@babel/plugin-syntax-jsx',
'react-hot-loader/babel',
],
},
};
export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) => ({
entry: [
root('../src/polyfills.ts'),
root(
env.playground
? 'playground/hmr-playground.tsx'
: env.bench ? '../benchmark/index.tsx' : 'index.tsx',
),
],
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'],
},
2018-03-17 16:11:52 +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-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?$/,
2018-03-17 18:58:28 +03:00
use: mode === 'production' ? [tsLoader(env)] : [tsLoader(env), babelHotLoader],
2018-03-13 13:58:22 +03:00
exclude: ['node_modules'],
},
{
test: /\.css$/,
use: {
loader: 'css-loader',
options: {
sourceMap: true,
minimize: true,
},
},
},
{
test: /node_modules\/(swagger2openapi|reftools)\/.*\.js$/,
use: {
2018-03-17 16:11:52 +03:00
loader: 'ts-loader',
options: {
2018-03-17 18:58:28 +03:00
transpileOnly: true,
instance: 'ts2js-transpiler-only',
compilerOptions: {
allowJs: true,
},
},
},
},
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-03-17 18:58:28 +03:00
template: env.playground ? 'demo/playground/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-13 13:58:22 +03:00
],
2018-03-17 18:58:28 +03:00
});