Update to webpack 4 + misc build process changes

This commit is contained in:
hensm
2018-11-13 21:51:09 +00:00
parent f23e1f68c2
commit c63531cdce
12 changed files with 3669 additions and 3332 deletions

View File

@@ -3,9 +3,9 @@
"license": "MIT", "license": "MIT",
"version": "0.1.0-alpha1", "version": "0.1.0-alpha1",
"scripts": { "scripts": {
"build": "node scripts/build.js", "build": "node bin/build.js",
"install-manifest": "node scripts/install-manifest.js", "install-manifest": "node bin/install-manifest.js",
"start-debug": "node scripts/start-debug.js", "start-debug": "node bin/start-debug.js",
"start": "node dist/app.js" "start": "node dist/app.js"
}, },
"dependencies": { "dependencies": {

View File

@@ -1,20 +1,29 @@
const spawn = require('child_process').spawn; const { spawn } = require('child_process');
const argv = require('minimist')(process.argv.slice(2)); const argv = require('minimist')(process.argv.slice(2));
const appId = argv.appId || "19A6F4AE";
const extensionName = "fx_cast";
const extensionId = "fx_cast@matt.tf";
const extensionVersion = "0.0.1";
// Default argument values
const { mirroringAppId = "19A6F4AE"
, mode = "development" } = argv;
const child = spawn( const child = spawn(
`webpack --env.appId=${appId} ` `webpack --env.extensionName=${extensionName} `
+ '&& web-ext build ' + `--env.extensionId=${extensionId} `
+ '--overwrite-dest ' + `--env.extensionVersion=${extensionVersion} `
+ '--source-dir ' + `--env.mirroringAppId=${mirroringAppId} `
+ '../dist/ext/unpacked ' + `--mode=${mode} `
+ '--artifacts-dir ' + `${argv.watch ? "--watch" : ""} `
+ '../dist/ext ' + `&& web-ext build --overwrite-dest `
+ '&& mv ../dist/ext/*.zip ../dist/ext/ext.xpi' + `--source-dir ../dist/ext `
+ `--artifacts-dir ../dist/ext `
, { , {
shell: true shell: true
} }
); );
child.stdout.pipe(process.stdout); child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr); child.stderr.pipe(process.stderr);

6840
ext/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,23 @@
{ {
"scripts": { "scripts": {
"build": "node build.js", "build": "node build.js",
"watch": "webpack -d --watch" "watch": "node build.js --watch"
}, },
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.0", "@babel/core": "^7.1.5",
"babel-loader": "^7.1.2", "@babel/plugin-proposal-class-properties": "^7.1.0",
"babel-plugin-transform-class-properties": "^6.24.1", "@babel/plugin-proposal-do-expressions": "^7.0.0",
"babel-plugin-transform-do-expressions": "^6.22.0", "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "@babel/preset-env": "^7.1.5",
"babel-preset-env": "^1.6.1", "@babel/preset-react": "^7.0.0",
"babel-preset-react": "^6.24.1", "babel-loader": "^8.0.4",
"copy-webpack-plugin": "^4.3.1", "copy-webpack-plugin": "^4.3.1",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"react": "^16.2.0", "react": "^16.6.1",
"react-dom": "^16.2.0", "react-dom": "^16.6.1",
"web-ext": "^2.7.0", "uuid": "^3.2.1",
"webpack": "^3.10.0" "web-ext": "^2.9.1",
}, "webpack": "^4.25.1",
"dependencies": { "webpack-cli": "^3.1.2"
"uuid": "^3.2.1"
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"extension_name": { "extension_name": {
"message": "fx_cast" "message": "EXTENSION_NAME"
} }
, "extension_description": { , "extension_description": {
"message": "" "message": ""

View File

@@ -1,11 +1,11 @@
{ {
"name": "__MSG_extension_name__" "name": "__MSG_extension_name__"
, "description": "__MSG_extension_description__" , "description": "__MSG_extension_description__"
, "version": "0.0.1" , "version": "EXTENSION_VERSION"
, "applications": { , "applications": {
"gecko": { "gecko": {
"id": "fx_cast@matt.tf" "id": "EXTENSION_ID"
, "strict_min_version": "57.0" , "strict_min_version": "57.0"
} }
} }

View File

@@ -7,5 +7,5 @@ export default {
"https://www.netflix.com/*" "https://www.netflix.com/*"
] ]
, option_mirroringEnabled: false , option_mirroringEnabled: false
, option_mirroringAppId: MIRROR_CAST_APP_ID || "19A6F4AE" , option_mirroringAppId: MIRRORING_APP_ID
} }

View File

@@ -1,57 +1,74 @@
"use strict"; "use strict";
const path = require("path"); const path = require("path");
const webpack = require("webpack"); const webpack = require("webpack");
const webpack_copy = require("copy-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin");
const include_path = path.resolve(__dirname, "src"); const includePath = path.resolve(__dirname, "src");
const output_path = path.resolve(__dirname, "../dist/ext/unpacked"); const outputPath = path.resolve(__dirname, "../dist/ext/");
module.exports = (env) => ({ module.exports = (env) => ({
entry: { entry: {
"main" : `${include_path}/main.js` "main" : `${includePath}/main.js`
, "popup/bundle" : `${include_path}/popup/index.js` , "popup/bundle" : `${includePath}/popup/index.js`
, "options/bundle" : `${include_path}/options/index.jsx` , "options/bundle" : `${includePath}/options/index.jsx`
, "shim/bundle" : `${include_path}/shim/index.js` , "shim/bundle" : `${includePath}/shim/index.js`
, "content" : `${include_path}/content.js` , "content" : `${includePath}/content.js`
, "contentSetup" : `${include_path}/contentSetup.js` , "contentSetup" : `${includePath}/contentSetup.js`
, "mediaCast" : `${include_path}/mediaCast.js` , "mediaCast" : `${includePath}/mediaCast.js`
, "mirroringCast" : `${include_path}/mirroringCast.js` , "mirroringCast" : `${includePath}/mirroringCast.js`
, "messageRouter" : `${include_path}/messageRouter.js` , "messageRouter" : `${includePath}/messageRouter.js`
} }
, output: { , output: {
filename: "[name].js" filename: "[name].js"
, path: `${output_path}` , path: `${outputPath}`
} }
, plugins: [ , plugins: [
//, new webpack.optimize.CommonsChunkPlugin("lib/init.bundle")
new webpack.DefinePlugin({ new webpack.DefinePlugin({
"process.env.NODE_ENV": `"production"` "EXTENSION_NAME" : JSON.stringify(env.extensionName)
, "MIRROR_CAST_APP_ID": JSON.stringify(env.appId.toString() || "19A6F4AE") , "EXTENSION_ID" : JSON.stringify(env.extensionId)
, "EXTENSION_VERSION" : JSON.stringify(env.extensionVersion)
, "MIRRORING_APP_ID" : JSON.stringify(env.mirroringAppId)
}) })
// Ext copy assets // Copy static assets
, new webpack_copy([{ , new CopyWebpackPlugin([{
from: `${include_path}` from: includePath
, to: `${output_path}` , to: outputPath
, ignore: [ "*.js" ] , 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;
}
}]) }])
] ]
, devtool: "eval-source-map" , mode: "development"
, module: { , module: {
loaders: [ rules: [
{ {
test: /\.jsx?$/ test: /\.jsx?$/
, include: `${include_path}` , include: `${includePath}`
, loader: "babel-loader" , use: {
, options: { loader: "babel-loader"
presets: [ "react" ] , options: {
, plugins: [ presets: [
"transform-class-properties" "@babel/preset-react"
, "transform-do-expressions" ]
, "transform-object-rest-spread" , plugins: [
] "@babel/proposal-class-properties"
, "@babel/proposal-do-expressions"
, "@babel/proposal-object-rest-spread"
]
}
} }
} }
] ]

View File

@@ -3,7 +3,9 @@
"postinstall": "npm run postinstall:app && npm run postinstall:ext", "postinstall": "npm run postinstall:app && npm run postinstall:ext",
"postinstall:app": "npm install ./app --prefix ./app", "postinstall:app": "npm install ./app --prefix ./app",
"postinstall:ext": "npm install ./ext --prefix ./ext", "postinstall:ext": "npm install ./ext --prefix ./ext",
"build": "npm run build --prefix ./app && npm run build --prefix ./ext --", "build": "npm run build:app && npm run build:ext",
"build:app": "npm run build --prefix ./app",
"build:ext": "npm run build --prefix ./ext",
"test": "jasmine --config=jasmine.json", "test": "jasmine --config=jasmine.json",
"install-manifest": "npm run install-manifest --prefix ./app" "install-manifest": "npm run install-manifest --prefix ./app"
}, },