-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.make.js
95 lines (80 loc) · 2.04 KB
/
webpack.make.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
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function makeWebpackConfig(options) {
/**
* Environment type
* BUILD is for generating minified builds
*/
var BUILD = !!options.BUILD;
var config = {};
if (BUILD) {
config.devtool = 'source-map';
} else {
config.devtool = 'eval';
}
// cache the build
config.cache = true;
config.entry = {
app: './src/app.js'
};
config.output = {
// absolute output directory
path: path.join(__dirname, '/dist'),
// output path from the view of the page
// uses webpack-dev-server in development
publicPath: BUILD ? '/' : 'http://localhost:8080/',
// filename for entry points
// only adds hash in build mode
filename: BUILD ? '[name].[hash].js' : '[name].bundle.js',
// filename for entry points
// only adds hash in build mode
chunkFilename: BUILD ? '[name].[hash].js' : '[name].bundle.js'
};
config.plugins = [];
// Skip rendering index.html in test mode
// Reference: https://github.com/ampedandwired/html-webpack-plugin
// Render index.html
config.plugins.push(
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
minify: BUILD ? { removeAttributeQuotes: true } : false
})
)
/**
* Transform JS source code using Babel configured to Stage 0, transform CSS
* source code using PostCSS and require binary files with file-loader.
*/
config.module = {
preLoaders: [],
loaders: [{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
exclude: /node_modules/,
loaders: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loader: 'file'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(ttf|eot|svg)(\?.*)?$/,
loader: "file"
}]
};
config.devServer = {
contentBase: './dist',
stats: {
colors: true,
}
};
return config;
};