Use modified outputPath for static assets

This commit is contained in:
hensm
2018-12-06 13:31:13 +00:00
parent 0ece4968cf
commit d3dba84186
2 changed files with 87 additions and 88 deletions

View File

@@ -33,7 +33,15 @@ if (argv.package) {
// Import webpack config and specify env values // Import webpack config and specify env values
const webpackConfig = require("./webpack.config.js")({ 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" , extensionId: "fx_cast@matt.tf"
, extensionVersion: "0.0.1" , extensionVersion: "0.0.1"
, mirroringAppId: argv.mirroringAppId , mirroringAppId: argv.mirroringAppId
@@ -42,14 +50,6 @@ const webpackConfig = require("./webpack.config.js")({
// Add mode to config // Add mode to config
webpackConfig.mode = argv.mode; 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 // Clean
fs.removeSync(DIST_PATH); fs.removeSync(DIST_PATH);

View File

@@ -1,79 +1,78 @@
"use strict"; "use strict";
const path = require("path"); const path = require("path");
const webpack = require("webpack"); const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin");
const includePath = path.resolve(__dirname, "src"); const includePath = path.resolve(__dirname, "src");
const outputPath = path.resolve(__dirname, "../dist/ext/unpacked");
module.exports = (env) => ({
module.exports = (env) => ({ entry: {
entry: { "main" : `${includePath}/main.js`
"main" : `${includePath}/main.js` , "popup/bundle" : `${includePath}/popup/index.jsx`
, "popup/bundle" : `${includePath}/popup/index.jsx` , "options/bundle" : `${includePath}/options/index.jsx`
, "options/bundle" : `${includePath}/options/index.jsx` , "shim/bundle" : `${includePath}/shim/index.js`
, "shim/bundle" : `${includePath}/shim/index.js` , "content" : `${includePath}/content.js`
, "content" : `${includePath}/content.js` , "contentSetup" : `${includePath}/contentSetup.js`
, "contentSetup" : `${includePath}/contentSetup.js` , "mediaCast" : `${includePath}/mediaCast.js`
, "mediaCast" : `${includePath}/mediaCast.js` , "mirroringCast" : `${includePath}/mirroringCast.js`
, "mirroringCast" : `${includePath}/mirroringCast.js` , "messageRouter" : `${includePath}/messageRouter.js`
, "messageRouter" : `${includePath}/messageRouter.js` }
} , output: {
, output: { filename: "[name].js"
filename: "[name].js" , path: `${env.outputPath}`
, path: `${outputPath}` }
} , plugins: [
, plugins: [ new webpack.DefinePlugin({
new webpack.DefinePlugin({ "EXTENSION_NAME" : JSON.stringify(env.extensionName)
"EXTENSION_NAME" : JSON.stringify(env.extensionName) , "EXTENSION_ID" : JSON.stringify(env.extensionId)
, "EXTENSION_ID" : JSON.stringify(env.extensionId) , "EXTENSION_VERSION" : JSON.stringify(env.extensionVersion)
, "EXTENSION_VERSION" : JSON.stringify(env.extensionVersion) , "MIRRORING_APP_ID" : JSON.stringify(env.mirroringAppId)
, "MIRRORING_APP_ID" : JSON.stringify(env.mirroringAppId) })
})
// Copy static assets
// Copy static assets , new CopyWebpackPlugin([{
, new CopyWebpackPlugin([{ from: includePath
from: includePath , to: env.outputPath
, to: outputPath , ignore: [ "*.js", "*.jsx" ]
, ignore: [ "*.js", "*.jsx" ] , transform (content, path) {
, transform (content, path) { // Access to variables in static files
// Access to variables in static files if (path.endsWith(".json")) {
if (path.endsWith(".json")) { return Buffer.from(content.toString()
return Buffer.from(content.toString() .replace("EXTENSION_NAME", env.extensionName)
.replace("EXTENSION_NAME", env.extensionName) .replace("EXTENSION_ID", env.extensionId)
.replace("EXTENSION_ID", env.extensionId) .replace("EXTENSION_VERSION", env.extensionVersion)
.replace("EXTENSION_VERSION", env.extensionVersion) .replace("MIRRORING_APP_ID", env.mirroringAppId));
.replace("MIRRORING_APP_ID", env.mirroringAppId)); }
}
return content;
return content; }
} }])
}]) ]
] , mode: "development"
, mode: "development" , module: {
, module: { rules: [
rules: [ {
{ test: /\.jsx?$/
test: /\.jsx?$/ , resolve: {
, resolve: { extensions: [ ".js", ".jsx" ]
extensions: [ ".js", ".jsx" ] }
} , include: `${includePath}`
, include: `${includePath}` , use: {
, use: { loader: "babel-loader"
loader: "babel-loader" , options: {
, options: { presets: [
presets: [ "@babel/preset-react"
"@babel/preset-react" ]
] , plugins: [
, plugins: [ "@babel/proposal-class-properties"
"@babel/proposal-class-properties" , "@babel/proposal-do-expressions"
, "@babel/proposal-do-expressions" , "@babel/proposal-object-rest-spread"
, "@babel/proposal-object-rest-spread" ]
] }
} }
} }
} ]
] }
} });
});