This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
/
webpack.config.js
85 lines (77 loc) · 2.19 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
85
/* eslint-disable import/no-extraneous-dependencies, no-console */
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const WebpackNotifierPlugin = require('webpack-notifier');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
/* NODE_ENV */
const NODE_ENV = process.env.NODE_ENV || 'development';
const isProd = NODE_ENV === 'production';
const isDev = !isProd;
console.info(`
:--------- process.env.NODE_ENV: ${NODE_ENV} ---------:
`);
let config = {
module: {
loaders: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'babel!ts'
},
{
test: /\.s?css$/,
loader: ExtractTextPlugin.extract('css!postcss!sass')
}
]
},
ts: {
compilerOptions: {
"declaration": false
}
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
},
postcss: [autoprefixer({ browsers: ['last 2 versions'] })],
plugins: [
new WebpackNotifierPlugin({ title: 'Webpack' }),
new ExtractTextPlugin('bundle.css'),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV)
}
})
]
};
if (isDev) {
config = merge(config, { devtool: 'inline-source-map' });
}
if (isProd) {
config = merge(config, {
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.AggressiveMergingPlugin()
]
});
}
const counterConf = () => {
const base = path.join(process.cwd(), 'docs/example/counter/');
return merge({}, config, {
entry: [path.join(base, 'index.tsx'), path.join(base, 'index.scss')],
output: {
path: base,
filename: 'bundle.js'
},
devServer: {
contentBase: base,
inline: true,
noInfo: true
}
});
};
module.exports = [counterConf()];