This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
78 lines (73 loc) · 1.78 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
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const precss = require('precss');
const postcssCalc = require("postcss-calc");
const postcssColorFunction = require("postcss-color-function");
const postcssImport = require("postcss-import");
const NODE_ENV = process.env.NODE_ENV || 'development';
const __DEV__ = NODE_ENV === 'development';
const __PROD__ = NODE_ENV === 'production';
const __TEST__ = NODE_ENV === 'test';
module.exports = {
entry: './src/index.tsx',
output: {
path: __dirname,
filename: '/static/js/app.js'
},
resolve: {
extensions: ['', '.webpack.js', '.ts', '.tsx', '.js', '.json'],
},
module: {
preLoaders: [
{test: /\.tsx?$/, loader: 'tslint'},
],
loaders: [
{test: /\.tsx?$/, loader: 'ts'},
{test: /\.css$/, loader: "style!css!postcss"}
]
},
plugins: getPlugins(),
devtool: __DEV__ ? '#eval-source-map' : null,
devServer: {
port: 8080,
contentBase: './',
historyApiFallback: true,
},
tslint: {
emitErrors: false,
failOnHint: false,
formatter: 'verbose',
},
postcss: function (wp) {
return [
postcssImport({addDependencyTo: wp}),
autoprefixer,
precss,
postcssCalc,
postcssColorFunction,
];
}
};
// Build plugins list imperatively because null values throw errors.
function getPlugins() {
const plugins = [
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify(NODE_ENV)},
__DEV__,
__PROD__,
__TEST__,
}),
];
if (__PROD__) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
sourceMap: false,
})
);
plugins.push(new webpack.optimize.OccurrenceOrderPlugin(true));
}
return plugins;
}