-
Notifications
You must be signed in to change notification settings - Fork 60
/
webpack.config.js
executable file
·139 lines (133 loc) · 3.63 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const constants = require('../src/js/constants.js');
const configs = require('../src/js/configs.js');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const exec = require('child_process').spawnSync;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
const production = process.env.NODE_ENV === 'production';
// function that returns the github short revision
const revision = () => {
try {
return exec('git', ['rev-parse', '--short', 'HEAD'], { encoding: 'ascii' }).stdout.trim();
} catch (error) {
return '';
}
}
// the many plugins used
const plugins = [
new HtmlWebpackPlugin({
constants,
configs,
csp: production ? constants.contentSecurityPolicy : constants.localContentSecurityPolicy,
date: new Date().toISOString().substr(0, 10),
production,
revision: revision(),
title: 'Mozilla SSL Configuration Generator',
template: 'src/templates/index.ejs',
favicon: 'src/images/favicon.png'
}),
new CopyWebpackPlugin({
patterns: [
{from: 'config/CNAME'},
{from: 'src/static'},
{from: 'src/js/analytics.js'}
]
}),
new MiniCssExtractPlugin({
filename: '[contenthash].index.css',
})
];
// either we analyze or watch
if (process.env.NODE_ENV === 'analyze') {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
plugins.push(
new BundleAnalyzerPlugin({})
);
} else if (process.env.NODE_ENV === 'development') {
const BrowserSyncWebpackPlugin = require('browser-sync-v3-webpack-plugin');
plugins.push(
new BrowserSyncWebpackPlugin({
host: 'localhost',
port: 5500,
server: {
baseDir: 'build'
}
})
);
}
module.exports = {
output: {
crossOriginLoading: 'anonymous',
library: 'SSLConfigGenerator',
libraryTarget: 'var',
path: production ? path.resolve(__dirname, '..', 'docs') : path.resolve(__dirname, '..', 'build'),
filename: '[contenthash].[name]'
},
stats: {
errorDetails: true,
children: true
},
resolve: {
fallback: {
"path": require.resolve("path-browserify")
}
},
entry: {
'index.js': ['regenerator-runtime/runtime', path.resolve(__dirname, '..', 'src', 'js', 'index.js')]
},
mode: production ? 'production' : 'development',
devtool: production ? undefined : 'source-map',
module: {
rules: [
{
test: /\.ejs$/,
use: ['ejs-easy-loader'],
},
{
test: /\.js$/,
include: path.resolve(__dirname, '..', 'src'),
use: [{
loader: 'babel-loader',
options: {
babelrc: false,
plugins: [
'@babel/plugin-transform-object-rest-spread'
],
presets: [
['@babel/preset-env', {
'targets': {
'ie': 11
},
'shippedProposals': true
}]
]
}
}]
},
{
test: /\.(sa|sc|c)ss$/,
//include: path.resolve(__dirname, '..', 'src'),
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader', // Run post css actions
options: {
postcssOptions: {
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
require('autoprefixer')
];
}
}
}
},
'sass-loader'
]
}
]
},
plugins: plugins,
};