UNPKG

1.46 kBJavaScriptView Raw
1'use strict';
2
3const HTMLWebpackPlugin = require('html-webpack-plugin');
4const Webpack = require('webpack');
5
6module.exports = (options) => {
7
8 const { isBuild, entry, output, template = false, port = 3000 } = options;
9
10 const devtool = !isBuild && 'source-map';
11
12 const devServer = {
13 port,
14 historyApiFallback: true,
15 inline: !isBuild,
16 hot: !isBuild,
17 stats: {
18 assets: true,
19 children: false,
20 chunks: false,
21 hash: false,
22 modules: false,
23 publicPath: true,
24 timings: true,
25 version: false,
26 warnings: true,
27 colors: {
28 green: '\u001b[32m',
29 }
30 }
31 };
32
33 const loaders = [
34 {test: /\.js$/, use: 'babel-loader' }
35 ];
36
37 const plugins = [new Webpack.NamedModulesPlugin()];
38
39 if (!isBuild)
40 plugins.push(new Webpack.HotModuleReplacementPlugin());
41
42 plugins.push(new HTMLWebpackPlugin({
43 filename: `index.html`,
44 template,
45 cache: true,
46 inject: 'body',
47 minify: isBuild && {
48 collapseWhitespace: true,
49 removeComments: true,
50 removeRedundantAttributes: true,
51 removeScriptTypeAttributes: true,
52 useShortDoctype: true,
53 removeEmptyAttributes: true,
54 removeStyleLinkTypeAttributes: true,
55 keepClosingSlash: true,
56 minifyJS: true,
57 minifyCSS: true,
58 minifyURLs: true,
59 },
60 }));
61
62 return {
63 entry,
64 output,
65 devtool,
66 devServer,
67 module: {
68 loaders
69 },
70 plugins
71 };
72
73};
\No newline at end of file