-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
117 lines (114 loc) · 3.36 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* jshint esversion: 6 */
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const ESLintPlugin = require('eslint-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UnusedWebpackPlugin = require('unused-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CopyPlugin = require('copy-webpack-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
const port = process.env.PORT || 3000;
const isHTTPS = process.env.PROTOCOL && process.env.PROTOCOL === 'HTTPS';
const bundleAnalysis = process.env.ANALYSIS || false; // enable the interactive bundle analyser and the Unused component analyzer
const isFixedPublicPath = process.env.FIXEDPATH || false;
module.exports = {
entry: path.resolve(__dirname, './src/index.jsx'),
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(png|jp(e*)g|svg|eot|woff|ttf)$/,
use: [
{
loader: 'file-loader',
options: {
publicPath: '/',
name: '[path][name].[ext]',
},
},
],
},
],
},
resolve: {
extensions: ['*', '.js', '.jsx'],
},
output: {
path: path.resolve(__dirname, './build'),
filename: '[name].[contenthash].js',
publicPath: isFixedPublicPath ? 'https://campaigns.wevote.us/' : '/',
},
plugins: [
new CleanWebpackPlugin(),
new ESLintPlugin({ failOnError: false, failOnWarning: false }),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: 'We Vote Action',
template: path.resolve(__dirname, './src/index.html'),
}),
...(bundleAnalysis ? [
new UnusedWebpackPlugin({ // Set ANALYSIS to true to list (likely) unused files
directories: [path.join(__dirname, 'src')],
exclude: [
'/**/cert/',
'/**/global/svg-icons/',
'/*.test.js',
'/robots.txt',
],
root: __dirname,
}),
new BundleAnalyzerPlugin(),
] : []),
new CopyPlugin({
patterns: [
{ from: 'src/robots.txt', to: '.' },
{ from: 'src/css/', to: 'css/' },
{
from: 'src/img',
to: 'img/',
globOptions: { ignore: ['DO-NOT-BUNDLE/**/*']},
},
{
from: 'src/javascript/',
to: 'javascript/',
},
],
}),
new MomentLocalesPlugin(),
new WebpackShellPluginNext({
onBuildEnd: {
scripts: ['node ./src/js/common/node/webPackPostBuild.js'],
blocking: false,
parallel: true,
},
}),
],
devServer: (isHTTPS ? {
contentBase: path.resolve(__dirname, './build'),
https: {
key: fs.readFileSync('./src/cert/server.key'),
cert: fs.readFileSync('./src/cert/server.crt'),
},
host: 'localhost',
port,
public: `localhost:${port}`,
historyApiFallback: true,
open: true,
disableHostCheck: true,
} : {
contentBase: path.resolve(__dirname, './build'),
host: 'localhost',
port,
public: `localhost:${port}`,
historyApiFallback: true,
open: true,
}),
devtool: 'source-map',
};