-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.js
104 lines (89 loc) · 2.52 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
const path = require('path')
const webpack = require('webpack')
const GenerateJsonPlugin = require('generate-json-webpack-plugin')
const ExtensionReloader = require('webpack-extension-reloader')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const ZipPlugin = require('zip-webpack-plugin')
const pkg = require('./package.json')
const distFolderName = 'unpacked-extension'
module.exports = ({ browser } = {}, { mode }) => {
const isProduction = mode === 'production'
const isChrome = browser === 'chrome'
const manifest = {
...pkg.extensionManifest,
version: pkg.version,
description: pkg.description,
}
if (isChrome) {
delete manifest.applications
}
const config = {
mode,
devtool: 'inline-source-map',
entry: {
'content-script': path.join(__dirname, 'src', 'entry-content-script.js'),
background: path.join(__dirname, 'src', 'entry-background.js'),
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, distFolderName),
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
module: {
rules: [
{
test: /\.(css$)/,
use: ['style-loader', 'css-loader'],
exclude: /node_modules/,
},
{
test: /\.(png|svg)/i,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['babel-plugin-styled-components'],
},
},
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.DISPLAY_NAME': JSON.stringify(pkg.displayName),
'process.env.VERSION': JSON.stringify(pkg.version),
}),
new GenerateJsonPlugin('manifest.json', manifest),
new ExtensionReloader({
manifest: path.resolve(__dirname, distFolderName, 'manifest.json'),
}),
],
}
if (isProduction) {
delete config.devtool
config.plugins[config.plugins.length - 1] = new ZipPlugin({
path: '../',
filename: `tako-github-file-tree-${browser}.zip`,
})
}
return config
}