forked from mozilla/FirefoxColor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.extension.js
75 lines (66 loc) · 1.96 KB
/
webpack.extension.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
/* eslint import/no-extraneous-dependencies: off */
const path = require("path");
const merge = require("webpack-merge");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const GenerateAssetWebpackPlugin = require("generate-asset-webpack-plugin");
const packageMeta = require("./package.json");
const { siteUrl, siteId, nodeEnv, webpackConfig } = require("./webpack.common.js");
module.exports = merge(webpackConfig, {
entry: {
background: "./src/extension/background",
contentScript: "./src/extension/contentScript"
},
output: {
path: path.resolve(__dirname, "build/extension"),
filename: "[name].js"
},
plugins: [
new GenerateAssetWebpackPlugin({
filename: "manifest.json",
fn: buildManifest
}),
new CopyWebpackPlugin([
{ from: "LICENSE" },
{ from: "src/images/icon.svg", to: "images/" },
{ from: "src/images/logo.svg", to: "images/" }
])
]
});
function buildManifest(compilation, cb) {
const {
name,
version,
description,
author,
homepage,
extensionManifest
} = packageMeta;
const manifest = Object.assign({}, extensionManifest, {
manifest_version: 2,
// HACK: Accept override in extensionManifest - npm disallows caps &
// spaces, but we want them in an extension name
name: extensionManifest.name || name,
version,
description,
author,
homepage_url: homepage
});
let idSuffix = [];
if (siteId) {
idSuffix.push(siteId);
}
if (nodeEnv === "development") {
idSuffix.push("dev");
}
if (idSuffix.length > 0) {
idSuffix = idSuffix.join("-");
manifest.applications.gecko.id =
manifest.applications.gecko.id.replace("@", `-${idSuffix}@`);
manifest.name = `${manifest.name} (${idSuffix})`;
}
// Configure content script to run on SITE_URL, omitting port if any
manifest.content_scripts[0].matches = [
`${siteUrl.replace(/:(\d+)\/?$/, "/")}*`
];
return cb(null, JSON.stringify(manifest, null, " "));
}