Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (79 loc) · 2.22 KB
/
Copy pathwebpack.config.js
File metadata and controls
89 lines (79 loc) · 2.22 KB
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
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const CopyPlugin = require('copy-webpack-plugin')
const GenerateJsonPlugin = require('generate-json-webpack-plugin')
const { merge } = require('webpack-merge')
const rootDir = path.resolve(__dirname)
const srcDir = path.join(rootDir, 'src')
const destDir = path.join(rootDir, 'build')
// Read version from package.json
const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json')).toString())
const version = packageJson.version
const manifestPath = path.join(srcDir, 'manifest.json')
const defaultManifest = JSON.parse(fs.readFileSync(manifestPath).toString())
// Update manifest versions from package.json
defaultManifest.version = version
const isDev = process.env.NODE_ENV === 'development'
function getEntryPoints() {
return {
options: path.join(srcDir, 'js', 'options.js'),
popup: path.join(srcDir, 'js', 'popup.js'),
sidepanel: path.join(srcDir, 'js', 'sidepanel.js'),
email_extractor: path.join(srcDir, 'js', 'email-extractor.js'),
scroll_capture: path.join(srcDir, 'js', 'scroll-capture.js'),
page_bridge: path.join(srcDir, 'js', 'page-bridge.js'),
background: path.join(srcDir, 'js', 'background.js'),
}
}
var common = {
mode: process.env.NODE_ENV || 'development',
performance: {
hints: false, // Extensions load from disk, not network
},
entry: getEntryPoints(),
output: {
path: destDir,
filename: '[name].js',
},
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
resolve: {
extensions: ['.js'],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: path.join(rootDir, 'public'),
to: destDir,
globOptions: {
ignore: ['**/.DS_Store'],
},
},
],
}),
new GenerateJsonPlugin('manifest.json', defaultManifest, null, 2),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
}),
],
}
function developmentConfig() {
return merge(common, {
devtool: 'cheap-module-source-map',
mode: 'development',
})
}
function productionConfig() {
return merge(common, {
mode: 'production',
})
}
module.exports = isDev ? developmentConfig() : productionConfig()