diff options
author | Ajay Ramachandran <[email protected]> | 2020-02-04 01:32:58 -0500 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-02-04 01:32:58 -0500 |
commit | 09a33c4252242f5184522af9973940c5a4954431 (patch) | |
tree | 8a2f284b55b871ae02d0f3a59f09eef43f20abfa /webpack | |
parent | da364b49f01f4af913319f83d4adeef8a9312132 (diff) | |
download | SponsorBlock-09a33c4252242f5184522af9973940c5a4954431.tar.gz SponsorBlock-09a33c4252242f5184522af9973940c5a4954431.zip |
Added manifest building.
Diffstat (limited to 'webpack')
-rw-r--r-- | webpack/webpack.common.js | 12 | ||||
-rw-r--r-- | webpack/webpack.dev.js | 2 | ||||
-rw-r--r-- | webpack/webpack.manifest.js | 65 | ||||
-rw-r--r-- | webpack/webpack.prod.js | 11 |
4 files changed, 82 insertions, 8 deletions
diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 70ea347a..162c8b50 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,9 +1,10 @@ const webpack = require("webpack"); const path = require('path'); const CopyPlugin = require('copy-webpack-plugin'); +const BuildManifest = require('./webpack.manifest'); const srcDir = '../src/'; -module.exports = { +module.exports = env => ({ entry: { popup: path.join(__dirname, srcDir + 'popup.ts'), background: path.join(__dirname, srcDir + 'background.ts'), @@ -34,11 +35,14 @@ module.exports = { }, plugins: [ // exclude locale files in moment - new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), new CopyPlugin([ - { from: '.', to: '../' } + { from: '.', to: '../', ignore: ['manifest.json'] } ], {context: 'public' } ), + new BuildManifest({ + browser: env.browser, + pretty: env.mode === "production" + }) ] -}; +}); diff --git a/webpack/webpack.dev.js b/webpack/webpack.dev.js index 274eb28d..6ceabb83 100644 --- a/webpack/webpack.dev.js +++ b/webpack/webpack.dev.js @@ -1,7 +1,7 @@ const merge = require('webpack-merge'); const common = require('./webpack.common.js'); -module.exports = merge(common, { +module.exports = env => merge(common(env), { devtool: 'inline-source-map', mode: 'development' });
\ No newline at end of file diff --git a/webpack/webpack.manifest.js b/webpack/webpack.manifest.js new file mode 100644 index 00000000..08e48b29 --- /dev/null +++ b/webpack/webpack.manifest.js @@ -0,0 +1,65 @@ +const webpack = require("webpack"); +const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); +const validateOptions = require('schema-utils'); + +const fs = require('fs'); + +const manifest = require("../manifest/manifest.json"); +const firefoxManifestExtra = require("../manifest/firefox-manifest-extra.json"); +const chromeManifestExtra = require("../manifest/chrome-manifest-extra.json"); + +// schema for options object +const schema = { + type: 'object', + properties: { + browser: { + type: 'string' + }, + pretty: { + type: 'boolean' + } + } +}; + +class BuildManifest { + constructor (options = {}) { + validateOptions(schema, options, "Build Manifest Plugin"); + + this.options = options; + } + + apply(compiler) { + const distManifestFile = path.resolve(__dirname, "../dist/manifest.json"); + + // Add missing manifest elements + if (this.options.browser.toLowerCase() === "firefox") { + mergeObjects(manifest, firefoxManifestExtra); + } else if (this.options.browser.toLowerCase() === "chrome" || this.options.browser.toLowerCase() === "chromium") { + mergeObjects(manifest, chromeManifestExtra); + } + + let result = JSON.stringify(manifest); + if (this.options.pretty) result = JSON.stringify(manifest, null, 2); + + fs.writeFileSync(distManifestFile, result); + } +} + +function mergeObjects(object1, object2) { + for (const key in object2) { + if (key in object1) { + if (Array.isArray(object1[key])) { + object1[key] = object1[key].concat(object2[key]); + } else if (typeof object1[key] == 'object') { + mergeObjects(object1[key], object2[key]); + } else { + object1[key] = object2[key]; + } + } else { + object1[key] = object2[key]; + } + } +} + +module.exports = BuildManifest;
\ No newline at end of file diff --git a/webpack/webpack.prod.js b/webpack/webpack.prod.js index daa65f51..65be616f 100644 --- a/webpack/webpack.prod.js +++ b/webpack/webpack.prod.js @@ -1,6 +1,11 @@ const merge = require('webpack-merge'); const common = require('./webpack.common.js'); -module.exports = merge(common, { - mode: 'production' -});
\ No newline at end of file +module.exports = env => { + let mode = "production"; + env.mode = mode; + + return merge(common(env), { + mode + }); +};
\ No newline at end of file |