-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
97 lines (94 loc) · 3.31 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
'use strict';
const path = require('node:path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const autoprefixer = require('autoprefixer');
const Dotenv = require('dotenv-webpack');
const webpack = require('webpack');
const distributionFolder = 'dist';
// eslint-disable-next-line jsdoc/require-jsdoc
module.exports = environment => {
let environmentPlugin;
if (environment.BIBLE_API_KEY !== undefined) {
environmentPlugin = new webpack.EnvironmentPlugin({'BIBLE_API_KEY': environment.BIBLE_API_KEY});
}
let developmentMode = environment === undefined || environment.NODE_ENV !== 'production';
return {
// mode: devMode ? 'development' : 'production',
mode: 'development',
entry: {
'background': './js/background.js',
'biblePreviewer': './js/biblePreviewer.js',
'options': './js/options.js',
'popup': './js/popup.js'
},
output: {
filename: 'js/[name].js',
path: path.resolve(__dirname, distributionFolder)
},
devtool: developmentMode ? 'source-map' : false,
module: {
rules: [
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
plugins: [
autoprefixer(),
]
}
}
},
'sass-loader'
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
'presets': [[
'@babel/preset-env', {
'targets':
{
'chrome': '58',
'firefox': '57'
}
}
]]
}
}
}
]
},
plugins: [
// If an environment variable exists for the BIBLE_API_KEY, then use that.
// Otherwise, use the value from the .env file.
environmentPlugin ?? new Dotenv(),
new CleanWebpackPlugin({verbose: true}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: '[id].css'
}),
new CopyWebpackPlugin({
patterns: [
'manifest.json',
'html/*.html',
'icons/**/*'
]
})
],
stats:
{
colors: true
}
};
};