2018-03-31 05:07:44 +00:00
|
|
|
const path = require('path');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2018-04-16 21:52:07 +00:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2018-03-31 05:07:44 +00:00
|
|
|
|
|
|
|
const env = process.env.NODE_ENV;
|
|
|
|
|
2018-04-16 21:52:07 +00:00
|
|
|
const prodPlugins = env === 'production' ? [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
sourceMap: true,
|
|
|
|
}),
|
|
|
|
] : [];
|
|
|
|
|
2018-03-31 05:07:44 +00:00
|
|
|
module.exports = {
|
2018-04-06 02:41:19 +00:00
|
|
|
entry: './src/transport.ts',
|
2018-03-31 05:07:44 +00:00
|
|
|
output: {
|
2018-04-16 21:52:07 +00:00
|
|
|
filename: env === 'production' ? '[name].min.js' : '[name].js',
|
2018-03-31 05:07:44 +00:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
|
},
|
2018-04-16 20:59:28 +00:00
|
|
|
mode: env === 'production' ? 'production' : 'development',
|
2018-03-31 05:07:44 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2018-04-06 02:41:19 +00:00
|
|
|
presets: [
|
|
|
|
'@babel/preset-env',
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
'@babel/proposal-class-properties',
|
|
|
|
'@babel/proposal-object-rest-spread',
|
|
|
|
],
|
|
|
|
cacheDirectory: env === 'development',
|
2018-03-31 05:07:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-04-06 02:41:19 +00:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: 'ts-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
2018-03-31 05:07:44 +00:00
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: env === 'production'
|
|
|
|
? ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: ['css-loader'],
|
|
|
|
})
|
|
|
|
: ['style-loader', 'css-loader'],
|
|
|
|
},
|
2018-04-15 08:02:54 +00:00
|
|
|
{
|
|
|
|
test: /\.png$/,
|
|
|
|
use: 'file-loader',
|
|
|
|
},
|
2018-03-31 05:07:44 +00:00
|
|
|
],
|
|
|
|
},
|
2018-04-06 02:41:19 +00:00
|
|
|
resolve: {
|
|
|
|
extensions: ['.tsx', '.ts', '.js'],
|
|
|
|
},
|
2018-03-31 05:07:44 +00:00
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.join(__dirname, 'index.html'),
|
|
|
|
}),
|
|
|
|
new ExtractTextPlugin({
|
|
|
|
disable: env === 'development',
|
|
|
|
filename: '[name].css',
|
|
|
|
}),
|
2018-04-16 21:52:07 +00:00
|
|
|
...prodPlugins,
|
2018-03-31 05:07:44 +00:00
|
|
|
],
|
2018-04-16 21:52:07 +00:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
devtool: env === 'production' ? 'source-map' : 'cheap-module-eval-source-map',
|
2018-03-31 05:07:44 +00:00
|
|
|
devServer: {
|
|
|
|
contentBase: path.join(__dirname, 'dist'),
|
|
|
|
host: '0.0.0.0',
|
|
|
|
port: 8888,
|
|
|
|
disableHostCheck: true,
|
|
|
|
},
|
|
|
|
};
|