-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
101 lines (89 loc) · 2.6 KB
/
webpack.config.babel.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import webpack from 'webpack';
import path from 'path';
import htmlWebpackPlugin from 'html-webpack-plugin';
import webpackMerge from 'webpack-merge';
import autoprefixer from 'autoprefixer';
const ROOT_PATH = path.resolve(__dirname);
const APP_PATH = path.resolve(ROOT_PATH, 'src');
const BUILD_PATH = path.resolve(ROOT_PATH, 'dist');
const TEST_PATH = path.resolve(ROOT_PATH, 'test');
const TARGET = process.env.npm_lifecycle_event;
const APP_CONFIG = {
entry: path.resolve(APP_PATH, 'index.js'),
output: {
path: BUILD_PATH,
filename: 'bundle.js'
}
};
process.env.BABEL_ENV = TARGET;
let config;
const COMMON = {
module: {
loaders: [{
test: /\.(js|jsx)$/,
loader: 'babel!eslint',
include: APP_PATH,
}, {
test: /\.css$/,
loader: 'style!css',
include: path.resolve(ROOT_PATH, 'node_modules', 'normalize.css')
}, {
test: /\.(sass|scss)$/,
loader: 'style!css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass?sourceMap&outputStyle=expanded&indentedSyntax'
}]
},
eslint: {
configFile: path.resolve(ROOT_PATH, '.eslintrc'),
emitError: false
},
postcss: () => { return [autoprefixer]; },
resolve: {
extensions: ['', '.js', '.jsx', 'sass'],
modulesDirectories: ["node_modules"],
alias: {
components: path.resolve(APP_PATH, 'components'),
containers: path.resolve(APP_PATH, 'containers'),
api: path.resolve(APP_PATH, 'api'),
reduxx: path.resolve(APP_PATH, 'reduxx'),
constants: path.resolve(APP_PATH, 'constants'),
config: path.resolve(APP_PATH, 'config'),
}
}
};
const DEV_SERVER = {
devtool: 'eval-source-map',
devServer: {
historyApiFallbacks: true,
hot: true,
port: 8000,
inline: true,
progress: true
},
plugins: [
new htmlWebpackPlugin({
title: "App"
}),
new webpack.HotModuleReplacementPlugin()
],
};
const PROD_BUILD = {
plugins: [
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
]
};
if (TARGET === 'start' || !TARGET) {
config = webpackMerge({...APP_CONFIG, ...COMMON}, DEV_SERVER);
} else if(TARGET === 'test') {
// TODO
} else if (TARGET === 'build') {
config = webpackMerge({...APP_CONFIG, ...COMMON}, PROD_BUILD);
}
export default config;