feat(phone/webpack): Allow for use of react-devtools in game

This is dynamically added to the bundle depending on the environment. In production, react-devtools will not be bundled. Build a development bundle using `yarn build:dev`
This commit is contained in:
Taso committed 2021-02-08 23:00:33 -05:00
1 parent eaf27f37ef
commit 7b6d49f661
6 files changed
+730 -54

No files matched your search

+3 -1
View File
@@ -64,6 +64,7 @@
"html-webpack-plugin": "^4.3.0", "html-webpack-plugin": "^4.3.0",
"ifdef-loader": "^2.1.5", "ifdef-loader": "^2.1.5",
"lint-staged": "^10.5.3", "lint-staged": "^10.5.3",
"react-devtools": "^4.10.1",
"react-test-renderer": "^16.13.1", "react-test-renderer": "^16.13.1",
"style-loader": "^0.23.1", "style-loader": "^0.23.1",
"svg-url-loader": "^2.3.2", "svg-url-loader": "^2.3.2",
@@ -77,7 +78,8 @@
"start": "react-scripts start", "start": "react-scripts start",
"watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js", "watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js",
"format": "prettier --write src/**/*.{js,jsx,ts,tsx,json,css,scss,md}", "format": "prettier --write src/**/*.{js,jsx,ts,tsx,json,css,scss,md}",
"build": "cross-env NODE_ENV=production webpack --config webpack/webpack.resources.js --color -p --progress --hide-modules --display-optimization-bailout", "build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --color -p --progress --hide-modules --display-optimization-bailout",
"build:dev": "cross-env NODE_ENV=development webpack --config webpack/dev.config.js --color -p --progress --hide-modules --display-optimization-bailout --analyze",
"test": "react-scripts test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}", "test": "react-scripts test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}",
"test:watch": "react-scripts test --watchAll --testMatch **/src/**/*.test.{ts,js,tsx}", "test:watch": "react-scripts test --watchAll --testMatch **/src/**/*.test.{ts,js,tsx}",
"eject": "react-scripts eject", "eject": "react-scripts eject",
+2 -1
View File
@@ -15,7 +15,8 @@
"noImplicitAny": false, "noImplicitAny": false,
"noEmit": true, "noEmit": true,
"jsx": "react", "jsx": "react",
"strictNullChecks": false "strictNullChecks": false,
"sourceMap": true
}, },
"include": ["src"] "include": ["src"]
} }
+21
View File
@@ -0,0 +1,21 @@
const path = require('path');
const CommonWebpack = require('./webpack.common');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = CommonWebpack({
mode: 'development',
devtool: 'inline-source-map',
entry: ['react-devtools', './src/index.tsx'],
// Output path
output: {
path: path.resolve(process.cwd(), 'build'),
filename: 'index.js',
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true,
minify: false,
}),
],
});
+18 -33
View File
@@ -1,12 +1,12 @@
const path = require("path"); const path = require('path');
const webpack = require("webpack"); const webpack = require('webpack');
module.exports = (options) => ({ module.exports = (options) => ({
mode: options.mode, mode: options.mode,
entry: options.entry, entry: options.entry,
output: { output: {
path: path.resolve(process.cwd(), "../resources/html"), path: path.resolve(process.cwd(), '../resources/html'),
filename: "[name].js", filename: '[name].js',
}, },
module: { module: {
rules: [ rules: [
@@ -14,7 +14,7 @@ module.exports = (options) => ({
test: /\.tsx?$/, test: /\.tsx?$/,
use: [ use: [
{ {
loader: "ts-loader", loader: 'ts-loader',
options: { options: {
transpileOnly: true, transpileOnly: true,
}, },
@@ -26,7 +26,7 @@ module.exports = (options) => ({
test: /\.jsx?$/, // Transform all .js and .jsx files required somewhere with Babel test: /\.jsx?$/, // Transform all .js and .jsx files required somewhere with Babel
exclude: /node_modules/, exclude: /node_modules/,
use: { use: {
loader: "babel-loader", loader: 'babel-loader',
}, },
}, },
{ {
@@ -35,23 +35,23 @@ module.exports = (options) => ({
// for a list of loaders, see https://webpack.js.org/loaders/#styling // for a list of loaders, see https://webpack.js.org/loaders/#styling
test: /\.css$/, test: /\.css$/,
exclude: /node_modules/, exclude: /node_modules/,
use: ["style-loader", "css-loader"], use: ['style-loader', 'css-loader'],
}, },
{ {
// Preprocess 3rd party .css files located in node_modules // Preprocess 3rd party .css files located in node_modules
test: /\.css$/, test: /\.css$/,
include: /node_modules/, include: /node_modules/,
use: ["style-loader", "css-loader"], use: ['style-loader', 'css-loader'],
}, },
{ {
test: /\.(eot|otf|ttf|woff|woff2)$/, test: /\.(eot|otf|ttf|woff|woff2)$/,
use: "file-loader", use: 'file-loader',
}, },
{ {
test: /\.svg$/, test: /\.svg$/,
use: [ use: [
{ {
loader: "svg-url-loader", loader: 'svg-url-loader',
options: { options: {
// Inline files smaller than 10 kB // Inline files smaller than 10 kB
limit: 10 * 1024, limit: 10 * 1024,
@@ -64,14 +64,14 @@ module.exports = (options) => ({
test: /\.(jpg|png|gif)$/, test: /\.(jpg|png|gif)$/,
use: [ use: [
{ {
loader: "url-loader", loader: 'url-loader',
options: { options: {
// Inline files smaller than 10 kB // Inline files smaller than 10 kB
limit: 10 * 1024, limit: 10 * 1024,
}, },
}, },
{ {
loader: "image-webpack-loader", loader: 'image-webpack-loader',
options: { options: {
mozjpeg: { mozjpeg: {
enabled: false, enabled: false,
@@ -87,7 +87,7 @@ module.exports = (options) => ({
optimizationLevel: 7, optimizationLevel: 7,
}, },
pngquant: { pngquant: {
quality: "65-90", quality: '65-90',
speed: 4, speed: 4,
}, },
}, },
@@ -96,32 +96,17 @@ module.exports = (options) => ({
}, },
{ {
test: /\.html$/, test: /\.html$/,
use: "html-loader", use: 'html-loader',
}, },
{ {
test: /\.(mp4|webm)$/, test: /\.(mp4|webm)$/,
use: { use: {
loader: "url-loader", loader: 'url-loader',
options: { options: {
limit: 10000, limit: 10000,
}, },
}, },
}, },
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: `ifdef-loader`,
options: {
DEBUG: options.mode !== "production",
version: 3,
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": true, // add this to use double slash comment instead of default triple slash
},
},
],
},
], ],
}, },
plugins: options.plugins.concat([ plugins: options.plugins.concat([
@@ -129,11 +114,11 @@ module.exports = (options) => ({
// inside your code for any environment checks; Terser will automatically // inside your code for any environment checks; Terser will automatically
// drop any unreachable code. // drop any unreachable code.
new webpack.EnvironmentPlugin({ new webpack.EnvironmentPlugin({
NODE_ENV: "development", NODE_ENV: options.mode,
}), }),
]), ]),
resolve: { resolve: {
modules: ["src", "node_modules"], modules: ['src', 'node_modules'],
extensions: [".js", ".jsx", ".ts", ".tsx", ".react.js"], extensions: ['.js', '.jsx', '.ts', '.tsx', '.react.js'],
}, },
}); });
@@ -1,12 +1,10 @@
const path = require('path'); const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const ResourceManifestPlugin = require('./webpack.fxmanifest.plugin');
const CopyPlugin = require('copy-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin');
module.exports = require('./webpack.common')({ module.exports = require('./webpack.common')({
mode: 'production', mode: 'production',
// In production, we skip all hot-reloading stuff
entry: [path.join(process.cwd(), 'src/index.tsx')], entry: [path.join(process.cwd(), 'src/index.tsx')],
plugins: [ plugins: [
@@ -26,7 +24,6 @@ module.exports = require('./webpack.common')({
}, },
inject: true, inject: true,
}), }),
new ResourceManifestPlugin(),
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [
{ {
+686 -16
View File
File diff suppressed because it is too large. Load diff