-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
60 lines (55 loc) · 1.41 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const path = require('path');
const webpack = require('webpack');
var nodeExternals = require('webpack-node-externals');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const isProd = process.argv.indexOf('-p') !== -1;
const webpackConfig = {
entry: { main: './index.ts' },
output: {
filename: './dist/[name].js',
libraryTarget: 'umd'
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
's-js': path.resolve(path.join(__dirname, 'node_modules', 's-js')) //https://github.com/webpack/webpack/issues/2134#issuecomment-192579511
}
},
target: isProd ? 'node' : undefined,
externals: isProd ? nodeExternals() : undefined,
devtool: isProd ? undefined : 'sourcemap',
module: {
rules: [
{
test: /\.tsx?$/,
use: ['surplus-loader', 'awesome-typescript-loader']
}
]
},
plugins: isProd ? [] : [new webpack.HotModuleReplacementPlugin()],
devServer: {
port: 3020,
open: true,
hot: true,
inline: true,
openPage: 'demo',
historyApiFallback: {
index: './demo/index.html'
}
}
};
if (isProd) {
webpackConfig.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 8889,
reportFilename: 'report.html',
openAnalyzer: true,
logLevel: 'info'
})
);
}
module.exports = webpackConfig;