This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
101 lines (94 loc) · 2.3 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
95
96
97
98
99
100
101
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const MinifyPlugin = require('babel-minify-webpack-plugin');
var prodPlugins = [];
var prodRules = [];
var performanceOpts = {};
// For production
if (process.env.NODE_ENV == 'production') {
// https://webpack.js.org/plugins/babel-minify-webpack-plugin/
const minifyOpts = {
removeConsole: true
};
const pluginOpts = {
comments: false
};
prodPlugins.push(new MinifyPlugin(minifyOpts, pluginOpts));
prodRules.push({
test: /\.js$/, // include .js files
enforce: 'pre', // preload the jshint loader
exclude: /(node_modules|bower_components)/,
use: {
loader: 'jshint-loader',
options: { // any jshint option http://www.jshint.com/docs/options/
camelcase: true,
emitErrors: false,
failOnHint: false,
reporter: function (errors) {
console.log(errors);
}
}
}
});
performanceOpts = {
hints: 'warning', // 'error' or false are valid too
maxEntrypointSize: 100000, // in bytes
maxAssetSize: 450000, // in bytes
};
}
const config = {
entry: {
app: './src/modules/init/main.js'
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
},
devServer: {
contentBase: path.join(__dirname, 'build'),
host: '0.0.0.0',
compress: true,
port: 9000
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: {
loader: 'css-loader',
options: {
minimize: true
}
}
})
}, {
test: /\.(gif|svg|png|jpg)$/,
use: 'file-loader'
}, {
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: 'file-loader'
}].concat(prodRules)
},
plugins: [
new HtmlWebpackPlugin({
template: './src/views/index.html'
}),
new ExtractTextPlugin('styles.css')
].concat(prodPlugins),
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, 'src')
]
},
performance: performanceOpts
};
module.exports = config;