This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathwebpack.config.js
124 lines (119 loc) · 3.28 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
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const GenerateJsonPlugin = require('generate-json-webpack-plugin')
const merge = require('webpack-merge')
const path = require('path')
// markdown convert to html
const marked = require('marked')
const renderer = new marked.Renderer()
module.exports = function (env, argv) {
console.log(env)
const [browser] = env.split(':')
const version = require('./manifest/common.json').version
const config = {
entry: {
background_page: './src/background_page/index.js',
content_script: './src/content_script/index.js',
content_script_loader: './src/content_script/loader.js',
info: './src/pages/info/index.js',
options: './src/pages/options/index.js'
},
output: {
path: path.join(__dirname, '/dist'),
filename: '[name].js',
sourceMapFilename: '[name].js.map' // always generate source maps
},
devtool: argv.mode === 'production' ? 'source-map' : 'inline-source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.md$/,
use: [
{
loader: 'html-loader'
},
{
loader: 'markdown-loader',
options: {
renderer
}
}
]
}
]
},
resolve: {
modules: ['./src', './node_modules'],
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat'
}
},
plugins: [
new CopyWebpackPlugin([
{
from: 'static'
},
{
context: 'src/options',
from: '**/default.json',
to: 'default_[folder].json'
},
{
context: 'src/options',
from: '**/config.json',
to: 'config_[folder].json'
}
]),
new GenerateJsonPlugin(
'manifest.json',
merge(
require('./manifest/common.json'),
require(`./manifest/${browser}.json`),
{ version }
),
null,
2
)
]
}
// extension id must be specified in calls to chrome.runtime.connect
// otherwise clients won't be able to reconnect to background page
// and background commands will stop working
const EXTENSION_ID = JSON.stringify(
browser === 'chrome'
? 'hhhpdkekipnbloiiiiaokibebpdpakdp'
: 'a0dd2b80-9ba1-224b-b5fe-3ae14f12d85d'
)
if (argv.mode === 'production') {
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
SAKA_DEBUG: JSON.stringify(false),
SAKA_VERSION: JSON.stringify(version),
SAKA_PLATFORM: JSON.stringify(browser),
EXTENSION_ID
})
])
} else {
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
SAKA_DEBUG: JSON.stringify(true),
SAKA_VERSION: JSON.stringify(version + ' dev'),
SAKA_PLATFORM: JSON.stringify(browser),
EXTENSION_ID
})
])
}
return config
}