diff --git a/ext/build.js b/ext/build.js index ceea454..f0f0746 100644 --- a/ext/build.js +++ b/ext/build.js @@ -33,7 +33,15 @@ if (argv.package) { // Import webpack config and specify env values const webpackConfig = require("./webpack.config.js")({ - extensionName: "fx_cast" + /** + * If watching files, output directly to dist. Unpacked + * directory is used as a staging area for web-ext builds. + */ + outputPath: argv.package + ? UNPACKED_PATH + : DIST_PATH + + , extensionName: "fx_cast" , extensionId: "fx_cast@matt.tf" , extensionVersion: "0.0.1" , mirroringAppId: argv.mirroringAppId @@ -42,14 +50,6 @@ const webpackConfig = require("./webpack.config.js")({ // Add mode to config webpackConfig.mode = argv.mode; -/** - * If watching files, output directly to dist. Unpacked - * directory is used as a staging area for web-ext builds. - */ -webpackConfig.output.path = argv.package - ? UNPACKED_PATH - : DIST_PATH; - // Clean fs.removeSync(DIST_PATH); diff --git a/ext/webpack.config.js b/ext/webpack.config.js index 034b62a..3d63c6a 100755 --- a/ext/webpack.config.js +++ b/ext/webpack.config.js @@ -1,79 +1,78 @@ -"use strict"; - -const path = require("path"); -const webpack = require("webpack"); -const CopyWebpackPlugin = require("copy-webpack-plugin"); - - -const includePath = path.resolve(__dirname, "src"); -const outputPath = path.resolve(__dirname, "../dist/ext/unpacked"); - -module.exports = (env) => ({ - entry: { - "main" : `${includePath}/main.js` - , "popup/bundle" : `${includePath}/popup/index.jsx` - , "options/bundle" : `${includePath}/options/index.jsx` - , "shim/bundle" : `${includePath}/shim/index.js` - , "content" : `${includePath}/content.js` - , "contentSetup" : `${includePath}/contentSetup.js` - , "mediaCast" : `${includePath}/mediaCast.js` - , "mirroringCast" : `${includePath}/mirroringCast.js` - , "messageRouter" : `${includePath}/messageRouter.js` - } - , output: { - filename: "[name].js" - , path: `${outputPath}` - } - , plugins: [ - new webpack.DefinePlugin({ - "EXTENSION_NAME" : JSON.stringify(env.extensionName) - , "EXTENSION_ID" : JSON.stringify(env.extensionId) - , "EXTENSION_VERSION" : JSON.stringify(env.extensionVersion) - , "MIRRORING_APP_ID" : JSON.stringify(env.mirroringAppId) - }) - - // Copy static assets - , new CopyWebpackPlugin([{ - from: includePath - , to: outputPath - , ignore: [ "*.js", "*.jsx" ] - , transform (content, path) { - // Access to variables in static files - if (path.endsWith(".json")) { - return Buffer.from(content.toString() - .replace("EXTENSION_NAME", env.extensionName) - .replace("EXTENSION_ID", env.extensionId) - .replace("EXTENSION_VERSION", env.extensionVersion) - .replace("MIRRORING_APP_ID", env.mirroringAppId)); - } - - return content; - } - }]) - ] - , mode: "development" - , module: { - rules: [ - { - test: /\.jsx?$/ - , resolve: { - extensions: [ ".js", ".jsx" ] - } - , include: `${includePath}` - , use: { - loader: "babel-loader" - , options: { - presets: [ - "@babel/preset-react" - ] - , plugins: [ - "@babel/proposal-class-properties" - , "@babel/proposal-do-expressions" - , "@babel/proposal-object-rest-spread" - ] - } - } - } - ] - } -}); +"use strict"; + +const path = require("path"); +const webpack = require("webpack"); +const CopyWebpackPlugin = require("copy-webpack-plugin"); + + +const includePath = path.resolve(__dirname, "src"); + +module.exports = (env) => ({ + entry: { + "main" : `${includePath}/main.js` + , "popup/bundle" : `${includePath}/popup/index.jsx` + , "options/bundle" : `${includePath}/options/index.jsx` + , "shim/bundle" : `${includePath}/shim/index.js` + , "content" : `${includePath}/content.js` + , "contentSetup" : `${includePath}/contentSetup.js` + , "mediaCast" : `${includePath}/mediaCast.js` + , "mirroringCast" : `${includePath}/mirroringCast.js` + , "messageRouter" : `${includePath}/messageRouter.js` + } + , output: { + filename: "[name].js" + , path: `${env.outputPath}` + } + , plugins: [ + new webpack.DefinePlugin({ + "EXTENSION_NAME" : JSON.stringify(env.extensionName) + , "EXTENSION_ID" : JSON.stringify(env.extensionId) + , "EXTENSION_VERSION" : JSON.stringify(env.extensionVersion) + , "MIRRORING_APP_ID" : JSON.stringify(env.mirroringAppId) + }) + + // Copy static assets + , new CopyWebpackPlugin([{ + from: includePath + , to: env.outputPath + , ignore: [ "*.js", "*.jsx" ] + , transform (content, path) { + // Access to variables in static files + if (path.endsWith(".json")) { + return Buffer.from(content.toString() + .replace("EXTENSION_NAME", env.extensionName) + .replace("EXTENSION_ID", env.extensionId) + .replace("EXTENSION_VERSION", env.extensionVersion) + .replace("MIRRORING_APP_ID", env.mirroringAppId)); + } + + return content; + } + }]) + ] + , mode: "development" + , module: { + rules: [ + { + test: /\.jsx?$/ + , resolve: { + extensions: [ ".js", ".jsx" ] + } + , include: `${includePath}` + , use: { + loader: "babel-loader" + , options: { + presets: [ + "@babel/preset-react" + ] + , plugins: [ + "@babel/proposal-class-properties" + , "@babel/proposal-do-expressions" + , "@babel/proposal-object-rest-spread" + ] + } + } + } + ] + } +});