forked from wevote/WebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.singleBundle.js
119 lines (115 loc) · 3.57 KB
/
webpack.config.singleBundle.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
118
119
// Steve 6/25/20: Forked from webpack.config.js at 0a58c2f "Dale John McGrew 6/19/20, 6:57 AM Removing external Polling Location widget from our stack. Instead, link people to external web page hosted by Democracy Works."
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UnusedWebpackPlugin = require('unused-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const { InjectManifest } = require('workbox-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); // Don't delete this!
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const port = process.env.PORT || 3000;
// Set isProduction to false, to enable the interactive bundle analyser and the Unused component analyzer
const isProduction = true; // Developers can set this to be false, but in git it should always be true
module.exports = {
mode: 'development',
entry: ['./src/js/index.js', './src/sass/loading-screen.scss', './src/sass/main.scss'],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build'),
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new CopyPlugin([
{ from: 'src/extension.html', to: '.' },
{ from: 'src/robots.txt', to: '.' },
{ from: 'src/css/', to: 'css/' },
{ from: 'src/img/',
to: 'img/',
ignore: ['DO-NOT-BUNDLE/**/*', 'welcome/partners/**/*'],
},
{ from: 'src/javascript/', to: 'javascript/' },
]),
// Strip from bundle.js, all moment.js locales except “en”
new MomentLocalesPlugin(),
new InjectManifest({
swSrc: './src/serviceWorker.js',
swDest: 'sw.js',
}),
...(isProduction ? [] : [
new UnusedWebpackPlugin({ // Set isProduction to false to list (likely) unused files
// Source directories and files, to exclude from unused file checking
directories: [path.join(__dirname, 'src')],
exclude: [
'**/cert/',
'**/DO-NOT-BUNDLE/',
'**/endorsement-extension/',
'**/global/photos/',
'**/global/svg-icons/',
'*.test.js',
'config-template.js',
'extension.html',
'robots.txt',
],
// Root directory (optional)
root: __dirname,
}),
new BundleAnalyzerPlugin(), // Set isProduction to false to start an (amazing) bundle size analyzer tool
]),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
name: 'css/[name].css',
},
},
{
loader: 'extract-loader',
},
{
loader: 'css-loader?-url',
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.(png|jp(e*)g|svg|eot|woff|ttf)$/,
use: [
{
loader: 'file-loader',
options: {
publicPath: '/',
name: 'img/[name].[ext]',
},
},
],
},
],
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.jsx'],
},
devServer: {
host: 'localhost',
port,
historyApiFallback: true,
open: true,
writeToDisk: true,
},
devtool: 'inline-cheap-module-source-map',
};