-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
84 lines (79 loc) · 2.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const path = require('path');
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const config = {
entry: ['./src/main.ts'],
output: {
libraryTarget: 'commonjs-module',
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
// Add resolve for `tsx` and `ts` files, otherwise Webpack would
// only look for common JavaScript file extension (.js)
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
// Activate source maps for the bundles in order to preserve the original
// source when the user debugs the application
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new DtsBundlePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true
},
output: {
comments: false
}
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
threshold: 10240,
minRatio: 0.8
})
],
module: {
// Webpack doesn't understand TypeScript files and a loader is needed.
// `node_modules` folder is excluded in order to prevent problems with
// the library dependencies, as well as `__tests__` folders that
// contain the tests for the library
loaders: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
}
]
},
externals: {
react: 'commonjs react',
'react-dom': 'commonjs react-dom'
}
};
module.exports = config;
function DtsBundlePlugin() {}
DtsBundlePlugin.prototype.apply = function(compiler) {
compiler.plugin('done', function() {
var dts = require('dts-bundle');
dts.bundle({
name: 'form-container',
main: 'dist/ts-build/main.d.ts',
out: '../index.d.ts',
removeSource: false // these are needed to --watch
});
});
};