-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
59 lines (57 loc) · 1.95 KB
/
webpack.config.js
File metadata and controls
59 lines (57 loc) · 1.95 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
const {execSync} = require('child_process')
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
const StringReplacePlugin = require("string-replace-webpack-plugin");
try{
execSync('rm -rf build')
}catch(e){}
const webpackConfig = {
entry: './src/index.js',
optimization: {
// We no not want to minimize our code.
minimize: false
},
output: {
path: __dirname + '/build',
filename: 'script.js'
}
}
if(process.env.NODE_ENV === 'release') {
const fs = require('fs')
const manifestJson = JSON.parse(fs.readFileSync('manifest.json', 'utf8'))
manifestJson.version = manifestJson.version.replace(/(\d+\.\d+\.)(\d+)/, (match, p1, p2) => `${p1}${parseInt(p2)+1}`)
fs.writeFileSync('manifest.json', JSON.stringify(manifestJson, null, 4))
webpackConfig.module = {
rules: [{
test: /findPathBFS/,
exclude: /node_modules/,
use:[{
loader: StringReplacePlugin.replace({
replacements: [{
pattern: /(\s{2,})fplog/,
replacement: (match, g1) => `${g1}console.log`
}]
})
}]
}, {
test: /index.js$/,
exclude: /node_modules/,
use:[{
loader: StringReplacePlugin.replace({
replacements: [{
pattern: /require\('.\/overrideConsoleError'\)/,
replacement: () => ''
}]
})
}]
}]
}
}
webpack(webpackConfig, function(err, stats) {
fs.copyFileSync('manifest.json', path.resolve('build', 'manifest.json'))
fs.copyFileSync('background.js', path.resolve('build', 'background.js'))
// execSync('cp ./manifest.json ./build/manifest.json')
// execSync('cp ./background.js ./build/background.js')
// execSync('rm build.zip; zip -r build.zip build/')
})