-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (85 loc) · 2.51 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
86
87
88
89
90
91
92
93
94
const Path = require('path');
const IS_DEBUG_BUILD = process.env.NODE_ENV !== "production";
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const ExtractSASS = new ExtractTextPlugin(`/css/index.css`);
console.log("DEBUG BUILD? " + IS_DEBUG_BUILD);
var cssRoot = IS_DEBUG_BUILD ? ('root=' + Path.join(__dirname)) : '';
module.exports = {
module: {
loaders: [
{ test: /\.css$/, }
]
}
}
module.exports = {
context: __dirname,
devtool: IS_DEBUG_BUILD ? "inline-sourcemap" : null,
// Entry Point
entry: (IS_DEBUG_BUILD ?
// FOR DEBUG BUILDS, USE HOT RELOADING
[
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/dev-server',
Path.join(__dirname, 'src/js/index.jsx')
] :
// IN PRODUCTION, DON'T
Path.join(__dirname, 'src/js/index.jsx')
),
// Put the built application in dist/
output: {
path: Path.join(__dirname, 'dist'),
filename: '/js/bundle.js',
},
// Define loaders
module: {
loaders: [
{ test: /\.css$/, loader: 'style!css', },
{ test: /.jsx?$/, loaders: [ 'babel-loader' ], include: Path.join(__dirname, 'src') },
{ test: /\.(ttf|eot|woff(2)?)(\?[a-z0-9]+)?$/, loader: 'file-loader?name=assets/fonts/[hash].[ext]' },
{ test: /\.(jpe?g|png|gif|svg)$/i, loader: 'file?hash=sha512&digest=hex&name=assets/images/[hash].[ext]' },
].concat(
(IS_DEBUG_BUILD ?
[
{ test: /\.scss$/, loaders: ['style', 'css?' + cssRoot, 'sass'] }
] :
[
{ test: /\.scss$/, loader: ExtractSASS.extract(['css', 'sass'], { publicPath: '/' }) }
]
)
)
},
resolve: {
root: [ Path.resolve('.') ],
extensions: [ '', '.js', '.jsx' ],
modulesDirectories: [ 'node_modules', __dirname, ],
},
plugins: [
new HtmlWebpackPlugin({
template: Path.join(__dirname, 'src/html/index.html'),
}),
ExtractSASS
].concat(
IS_DEBUG_BUILD ?
// DEBUG PLUGINS
[
new webpack.HotModuleReplacementPlugin()
] :
// PRODUCTION PLUGINS
[
// new webpack.optimize.DedupePlugin(),
// new webpack.optimize.OccurenceOrderPlugin(),
// new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
]
),
devServer: {
contentBase: Path.join(__dirname, 'dist/'),
hot: true,
host: '0.0.0.0',
port: 8080,
inline: true,
progress: true,
historyApiFallback: true,
}
};