-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
84 lines (78 loc) · 2.94 KB
/
webpack.prod.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
// tslint:disable:no-console
const { promisify } = require('util');
const chalk = require('chalk');
const exec = promisify(require('child_process').exec);
const mv = promisify(require('mv'));
const path = require('path');
const WebpackOnBuildPlugin = require('on-build-webpack');
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
const common = require('./webpack.common.js');
const BASE_DIR = __dirname;
const DIST_DIR = path.join(BASE_DIR, 'dist');
const ARTIFACTS_DIR = path.join(BASE_DIR, 'artifacts');
const CHROME_DOCKER_NAME = 'treffynnon/alpine-chrome-extension-pack';
module.exports = merge(common, {
devtool: 'source-map',
plugins: [
new UglifyJSPlugin({
parallel: true,
sourceMap: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
// runs commands after the build is complete to produce the chrome extension
// CRX file
new WebpackOnBuildPlugin(async stats => {
if (stats.compilation.errors.length === 0) {
try {
await exec(`${path.join(BASE_DIR, 'build-tools/chrome-pack.sh')} ${BASE_DIR}`);
const dest = path.join(
ARTIFACTS_DIR,
`whereby.com-meeting-room-helper-${process.env.npm_package_version}.crx`,
);
await mv(path.join(BASE_DIR, 'dist.crx'), dest);
console.log(chalk.green(`Build complete: ${dest}`));
} catch (e) {
console.error(chalk.red(e.message));
console.error(e);
process.exit(2);
}
}
}),
/*new WebpackOnBuildPlugin(async stats => {
const webExt = require('web-ext').default;
webExt.cmd.sign({
// These are command options derived from their CLI conterpart.
// In this example, --source-dir is specified as sourceDir.
apiKey: process.env.FIREFOX_API_KEY,
apiSecret: process.env.FIREFOX_API_SECRET,
artifactsDir: __dirname,
firefox: path.join(__dirname, 'dist'),
sourceDir: path.join(__dirname, 'dist'),
}, {
// These are non CLI related options for each function.
// You need to specify this one so that your NodeJS application
// can continue running after web-ext is finished.
shouldExitProgram: false,
})
.then( extensionRunner => {
// The command has finished. Each command resolves its
// promise with a different value.
console.log(extensionRunner);
// You can do a few things like:
// extensionRunner.reloadAllExtensions();
// extensionRunner.exit();
})
.catch(console.error);
}),*/
// produce a zip for uploading to Chrome webstore
new ZipPlugin({
filename: `whereby.com-meeting-room-helper-${process.env.npm_package_version}.zip`,
path: ARTIFACTS_DIR,
}),
],
});