Webpack 5 support with updated packages (#131)

- Update to Webpack 5
- Use @effortlessmotion dynamic html and inline source plugins
- Remove .clasp.json and use SAMPLE file
- Consistent prettier formatting throughout
- Update packages to latest versions

Co-authored-by: Kevin Malakoff <kmalakoff@gmail.com>
This commit is contained in:
Elisha Nuchi
2022-06-20 01:59:26 -04:00
committed by GitHub
parent 0adf784ba1
commit fd73dc051c
25 changed files with 7690 additions and 17891 deletions
-4
View File
@@ -1,4 +0,0 @@
{
"rootDir": "dist",
"scriptId": "...add scriptId here..."
}
+7
View File
@@ -0,0 +1,7 @@
{
"rootDir": "dist",
"scriptId": "...add scriptId here...",
"parentId": [
"...spreadsheet/doc url ID here..."
]
}
+5
View File
@@ -10,5 +10,10 @@
"import/no-extraneous-dependencies": "warn", "import/no-extraneous-dependencies": "warn",
"prefer-object-spread": "warn", "prefer-object-spread": "warn",
"spaced-comment":"off" "spaced-comment":"off"
},
"parserOptions": {
"babelOptions": {
"configFile": "./dev/.babelrc"
}
} }
} }
-1
View File
@@ -2,7 +2,6 @@
node_modules node_modules
# clasp files # clasp files
.clasp*
creds.json creds.json
# certs # certs
+1 -1
View File
@@ -113,7 +113,7 @@ You will need to update the `.clasp.json` file in the root of this project with
{ {
"scriptId": "1PY037hPcy................................................", "scriptId": "1PY037hPcy................................................",
"parentId": ["1Df30......................................."], "parentId": ["1Df30......................................."],
"rootDir": "./dist" "rootDir": "dist"
} }
``` ```
+3 -3
View File
@@ -7,20 +7,20 @@ const { FILENAME, PORT } = process.env;
const DevServer = () => { const DevServer = () => {
const iframe = React.useRef(null); const iframe = React.useRef(null);
useEffect(() => { useEffect(() => {
const handleRequest = event => { const handleRequest = (event) => {
const request = event.data; const request = event.data;
const { type, functionName, id, args } = request; const { type, functionName, id, args } = request;
if (type !== 'REQUEST') return; if (type !== 'REQUEST') return;
serverFunctions[functionName](...args) serverFunctions[functionName](...args)
.then(response => { .then((response) => {
iframe.current.contentWindow.postMessage( iframe.current.contentWindow.postMessage(
{ type: 'RESPONSE', id, status: 'SUCCESS', response }, { type: 'RESPONSE', id, status: 'SUCCESS', response },
`https://localhost:${PORT}` `https://localhost:${PORT}`
); );
}) })
.catch(err => { .catch((err) => {
iframe.current.contentWindow.postMessage( iframe.current.contentWindow.postMessage(
{ {
type: 'RESPONSE', type: 'RESPONSE',
+7543 -17749
View File
File diff suppressed because it is too large Load Diff
+47 -47
View File
@@ -8,7 +8,7 @@
}, },
"scripts": { "scripts": {
"test:integration": "jest --forceExit test/local-development.test", "test:integration": "jest --forceExit test/local-development.test",
"test:integration:extended": "cross-env IS_EXTENDED=1 jest --forceExit test/local-development.test", "test:integration:extended": "cross-env IS_EXTENDED=true jest --forceExit test/local-development.test",
"login": "clasp login", "login": "clasp login",
"setup": "rimraf .clasp.json && clasp create --type sheets --title \"My React Project\" --rootDir ./dist", "setup": "rimraf .clasp.json && clasp create --type sheets --title \"My React Project\" --rootDir ./dist",
"open": "clasp open --addon", "open": "clasp open --addon",
@@ -17,7 +17,7 @@
"build": "cross-env NODE_ENV=production webpack", "build": "cross-env NODE_ENV=production webpack",
"deploy:dev": "rimraf dist && npm run build:dev && npx clasp push", "deploy:dev": "rimraf dist && npm run build:dev && npx clasp push",
"deploy": "rimraf dist && npm run build && npx clasp push", "deploy": "rimraf dist && npm run build && npx clasp push",
"serve": "cross-env NODE_ENV=development webpack-dev-server", "serve": "cross-env NODE_ENV=development webpack serve",
"start": "npm run deploy:dev && npm run serve" "start": "npm run deploy:dev && npm run serve"
}, },
"keywords": [ "keywords": [
@@ -35,75 +35,75 @@
}, },
"dependencies": { "dependencies": {
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^17.0.2", "react": "^18.2.0",
"react-bootstrap": "^1.6.4", "react-bootstrap": "^2.4.0",
"react-dom": "^17.0.2", "react-dom": "^18.2.0",
"react-transition-group": "^4.4.2" "react-transition-group": "^4.4.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.17.6", "@babel/cli": "^7.17.6",
"@babel/core": "^7.17.8", "@babel/core": "^7.17.8",
"@babel/eslint-parser": "^7.17.0", "@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-class-properties": "^7.16.7", "@babel/plugin-proposal-class-properties": "^7.17.12",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3", "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.7", "@babel/plugin-proposal-optional-chaining": "^7.17.12",
"@babel/plugin-transform-object-assign": "^7.16.7", "@babel/plugin-transform-object-assign": "^7.16.7",
"@babel/polyfill": "^7.12.1", "@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.18.2",
"@babel/preset-react": "^7.16.7", "@babel/preset-react": "^7.17.12",
"@google/clasp": "2.3.1", "@effortlessmotion/dynamic-cdn-webpack-plugin": "^5.0.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.4", "@effortlessmotion/html-webpack-inline-source-plugin": "^1.0.3",
"@types/expect-puppeteer": "^4.4.7", "@google/clasp": "^2.4.1",
"@types/jest-environment-puppeteer": "^4.4.1", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@types/puppeteer": "^5.4.5", "@types/expect-puppeteer": "^5.0.0",
"@types/jest-environment-puppeteer": "^5.0.2",
"@types/puppeteer": "^5.4.6",
"@types/react": "^18.0.14",
"aws-sdk": "^2.1106.0", "aws-sdk": "^2.1106.0",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"babel-loader": "^8.2.4", "babel-loader": "^8.2.5",
"babel-plugin-add-module-exports": "^1.0.2", "babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0", "babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0", "babel-plugin-transform-es3-property-literals": "^6.22.0",
"copy-webpack-plugin": "^6.4.1", "copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.2", "cross-env": "^7.0.3",
"css-loader": "^3.6.0", "css-loader": "^6.7.1",
"dotenv": "^8.6.0", "dotenv": "^16.0.1",
"dynamic-cdn-webpack-plugin": "^5.0.0", "eslint": "^8.17.0",
"eslint": "^8.12.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^6.15.0", "eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^14.1.1", "eslint-config-standard": "^17.0.0",
"eslint-plugin-babel": "^5.3.1", "eslint-plugin-babel": "^5.3.1",
"eslint-plugin-googleappsscript": "^1.0.4", "eslint-plugin-googleappsscript": "^1.0.4",
"eslint-plugin-import": "^2.25.4", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.1.3", "eslint-plugin-jest": "^26.5.3",
"eslint-plugin-jsx-a11y": "^6.5.1", "eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1", "eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.29.4", "eslint-plugin-react": "^7.30.0",
"eslint-plugin-standard": "^4.1.0", "eslint-plugin-standard": "^5.0.0",
"gas-client": "^1.0.0", "gas-client": "^1.0.0",
"gas-lib": "^2.0.4", "gas-lib": "^2.0.4",
"gas-types-detailed": "^1.0.0", "gas-types-detailed": "^1.0.0",
"gas-webpack-plugin": "^1.2.3", "gas-webpack-plugin": "^2.2.2",
"html-webpack-inline-source-plugin": "0.0.10", "html-webpack-plugin": "^5.5.0",
"html-webpack-plugin": "^3.2.0", "jest": "^28.1.1",
"jest": "^27.5.1", "jest-environment-node": "^28.1.1",
"jest-environment-node": "^27.5.1", "jest-image-snapshot": "^5.1.0",
"jest-image-snapshot": "^4.5.1",
"mkdirp": "^1.0.4", "mkdirp": "^1.0.4",
"module-to-cdn": "^3.1.5", "module-to-cdn": "^3.1.5",
"prettier": "^1.19.1", "prettier": "^2.7.0",
"puppeteer": "^13.5.2", "puppeteer": "^14.3.0",
"puppeteer-extra": "^3.2.3", "puppeteer-extra": "^3.2.3",
"puppeteer-extra-plugin-stealth": "^2.9.0", "puppeteer-extra-plugin-stealth": "^2.9.0",
"react-refresh": "^0.10.0", "react-refresh": "^0.14.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"style-loader": "^1.3.0", "style-loader": "^3.3.1",
"tern": "^0.24.3", "terser-webpack-plugin": "^5.3.3",
"terser-webpack-plugin": "^2.3.8", "ts-loader": "^9.3.0",
"ts-loader": "^8.3.0", "webpack": "^5.73.0",
"webpack": "^4.44.1", "webpack-cli": "^4.10.0",
"webpack-cli": "^3.3.12", "webpack-dev-server": "^4.9.2"
"webpack-dev-server": "^3.11.3"
} }
} }
@@ -2,9 +2,7 @@ import React, { useState, ChangeEvent, FormEvent } from 'react';
import { Form, Button, Col, Row } from 'react-bootstrap'; import { Form, Button, Col, Row } from 'react-bootstrap';
interface FormInputProps { interface FormInputProps {
submitNewSheet: ( submitNewSheet: (sheetName: string) => {
sheetName: string
) => {
name: string; name: string;
index: number; index: number;
isActive: boolean; isActive: boolean;
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { TransitionGroup, CSSTransition } from 'react-transition-group'; import { TransitionGroup, CSSTransition } from 'react-transition-group';
import { Button, ListGroup } from 'react-bootstrap'; import { Button, ListGroup } from 'react-bootstrap';
import FormInput from './FormInput.tsx'; import FormInput from './FormInput';
// This is a wrapper for google.script.run that lets us use promises. // This is a wrapper for google.script.run that lets us use promises.
import { serverFunctions } from '../../utils/serverFunctions'; import { serverFunctions } from '../../utils/serverFunctions';
@@ -10,27 +10,18 @@ const SheetEditor = () => {
const [names, setNames] = useState([]); const [names, setNames] = useState([]);
useEffect(() => { useEffect(() => {
serverFunctions serverFunctions.getSheetsData().then(setNames).catch(alert);
.getSheetsData()
.then(setNames)
.catch(alert);
}, []); }, []);
const deleteSheet = sheetIndex => { const deleteSheet = (sheetIndex) => {
serverFunctions serverFunctions.deleteSheet(sheetIndex).then(setNames).catch(alert);
.deleteSheet(sheetIndex)
.then(setNames)
.catch(alert);
}; };
const setActiveSheet = sheetName => { const setActiveSheet = (sheetName) => {
serverFunctions serverFunctions.setActiveSheet(sheetName).then(setNames).catch(alert);
.setActiveSheet(sheetName)
.then(setNames)
.catch(alert);
}; };
const submitNewSheet = async newSheetName => { const submitNewSheet = async (newSheetName) => {
try { try {
const response = await serverFunctions.addSheet(newSheetName); const response = await serverFunctions.addSheet(newSheetName);
setNames(response); setNames(response);
@@ -56,7 +47,7 @@ const SheetEditor = () => {
<ListGroup> <ListGroup>
<TransitionGroup className="sheet-list"> <TransitionGroup className="sheet-list">
{names.length > 0 && {names.length > 0 &&
names.map(name => ( names.map((name) => (
<CSSTransition <CSSTransition
classNames="sheetNames" classNames="sheetNames"
timeout={500} timeout={500}
+1 -1
View File
@@ -1,6 +1,6 @@
/* needed to make consistent test snapshots across OSs */ /* needed to make consistent test snapshots across OSs */
body { body {
font-family: Arial, Helvetica, sans-serif !important; font-family: Arial !important;
} }
/* /*
@@ -4,9 +4,9 @@ import PropTypes from 'prop-types';
const FormInput = ({ submitNewSheet }) => { const FormInput = ({ submitNewSheet }) => {
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const handleChange = event => setInputValue(event.target.value); const handleChange = (event) => setInputValue(event.target.value);
const handleSubmit = event => { const handleSubmit = (event) => {
event.preventDefault(); event.preventDefault();
if (inputValue.length === 0) return; if (inputValue.length === 0) return;
@@ -11,29 +11,20 @@ const SheetEditor = () => {
useEffect(() => { useEffect(() => {
// Call a server global function here and handle the response with .then() and .catch() // Call a server global function here and handle the response with .then() and .catch()
serverFunctions serverFunctions.getSheetsData().then(setNames).catch(alert);
.getSheetsData()
.then(setNames)
.catch(alert);
}, []); }, []);
const deleteSheet = sheetIndex => { const deleteSheet = (sheetIndex) => {
serverFunctions serverFunctions.deleteSheet(sheetIndex).then(setNames).catch(alert);
.deleteSheet(sheetIndex)
.then(setNames)
.catch(alert);
}; };
const setActiveSheet = sheetName => { const setActiveSheet = (sheetName) => {
serverFunctions serverFunctions.setActiveSheet(sheetName).then(setNames).catch(alert);
.setActiveSheet(sheetName)
.then(setNames)
.catch(alert);
}; };
// You can also use async/await notation for server calls with our server wrapper. // You can also use async/await notation for server calls with our server wrapper.
// (This does the same thing as .then().catch() in the above handlers.) // (This does the same thing as .then().catch() in the above handlers.)
const submitNewSheet = async newSheetName => { const submitNewSheet = async (newSheetName) => {
try { try {
const response = await serverFunctions.addSheet(newSheetName); const response = await serverFunctions.addSheet(newSheetName);
setNames(response); setNames(response);
@@ -56,7 +47,7 @@ const SheetEditor = () => {
<FormInput submitNewSheet={submitNewSheet} /> <FormInput submitNewSheet={submitNewSheet} />
<TransitionGroup className="sheet-list"> <TransitionGroup className="sheet-list">
{names.length > 0 && {names.length > 0 &&
names.map(name => ( names.map((name) => (
<CSSTransition <CSSTransition
classNames="sheetNames" classNames="sheetNames"
timeout={500} timeout={500}
+4 -6
View File
@@ -14,20 +14,18 @@ export const getSheetsData = () => {
}); });
}; };
export const addSheet = sheetTitle => { export const addSheet = (sheetTitle) => {
SpreadsheetApp.getActive().insertSheet(sheetTitle); SpreadsheetApp.getActive().insertSheet(sheetTitle);
return getSheetsData(); return getSheetsData();
}; };
export const deleteSheet = sheetIndex => { export const deleteSheet = (sheetIndex) => {
const sheets = getSheets(); const sheets = getSheets();
SpreadsheetApp.getActive().deleteSheet(sheets[sheetIndex]); SpreadsheetApp.getActive().deleteSheet(sheets[sheetIndex]);
return getSheetsData(); return getSheetsData();
}; };
export const setActiveSheet = sheetName => { export const setActiveSheet = (sheetName) => {
SpreadsheetApp.getActive() SpreadsheetApp.getActive().getSheetByName(sheetName).activate();
.getSheetByName(sheetName)
.activate();
return getSheetsData(); return getSheetsData();
}; };
Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 40 KiB

+7 -4
View File
@@ -25,10 +25,13 @@ const srcTestFile = path.join(
'../src/client/dialog-demo-bootstrap/components/SheetEditor.jsx' '../src/client/dialog-demo-bootstrap/components/SheetEditor.jsx'
); );
const webpackDevServerReady = async process => { const webpackDevServerReady = async (process) => {
return new Promise(resolve => { console.log('Waiting for Webpack Dev Server to finish loading...');
process.stdout.on('data', data => { return new Promise((resolve) => {
if (data.includes('Compiled successfully.')) resolve(); process.stdout.on('data', (data) => {
if (data.includes('DEVELOPMENT: CLIENT - Dialog Demo Bootstrap')) {
resolve();
}
}); });
}); });
}; };
+5 -1
View File
@@ -6,11 +6,15 @@ const { readFile } = require('fs').promises;
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
const puppeteer = require('puppeteer'); const puppeteer = require('puppeteer');
const NodeEnvironment = require('jest-environment-node'); const NodeEnvironment = require('jest-environment-node').default;
const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup'); const DIR = path.join(os.tmpdir(), 'jest_puppeteer_global_setup');
class PuppeteerEnvironment extends NodeEnvironment { class PuppeteerEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}
async setup() { async setup() {
await super.setup(); await super.setup();
// get the wsEndpoint // get the wsEndpoint
+10 -6
View File
@@ -2,11 +2,15 @@
/** /**
* Reference: https://github.com/americanexpress/jest-image-snapshot/blob/main/examples/image-reporter.js * Reference: https://github.com/americanexpress/jest-image-snapshot/blob/main/examples/image-reporter.js
* *
* To enable this image reporter, add it to your `jest.config.js` "reporters" definition: * To enable this image reporter, add it to your `jest.config.js` "reporters" definition:
* "reporters": [ "default", "<rootDir>/image-reporter.js" ] * "reporters": [ "default", "<rootDir>/image-reporter.js" ]
* *
* Image Reporter may not work with jest's --forceExit flag * Note: Image Reporter may not work with jest's --forceExit flag
*
* Note: If image reporter doesn't work in pipeline can try running as standalone script
* by creating a separate script file and running like this:
* "test:integration": "jest test/local-development.test || node test/utils/image-reporter-standalone.js"
*/ */
const fs = require('fs'); const fs = require('fs');
@@ -44,9 +48,9 @@ class ImageReporter {
'./test/__image_snapshots__/', './test/__image_snapshots__/',
'./test/__image_snapshots__/__diff_output__/', './test/__image_snapshots__/__diff_output__/',
]; ];
targetDirectories.forEach(targetDirectory => { targetDirectories.forEach((targetDirectory) => {
fs.readdirSync(targetDirectory, { withFileTypes: true }).forEach( fs.readdirSync(targetDirectory, { withFileTypes: true }).forEach(
dirent => { (dirent) => {
if (!dirent.isFile()) return; if (!dirent.isFile()) return;
const path = `images/${dirent.name}`; const path = `images/${dirent.name}`;
const params = { const params = {
@@ -55,7 +59,7 @@ class ImageReporter {
Key: path, Key: path,
ContentType: 'image/png', ContentType: 'image/png',
}; };
s3.putObject(params, err => { s3.putObject(params, (err) => {
if (err) { if (err) {
console.log(err, err.stack); console.log(err, err.stack);
} else { } else {
+2 -2
View File
@@ -1,4 +1,4 @@
const openAddon = async page => { const openAddon = async (page) => {
await page.goto(process.env.SHEET_URL); await page.goto(process.env.SHEET_URL);
await page.click('a:nth-child(2)'); // click on signin button await page.click('a:nth-child(2)'); // click on signin button
@@ -22,7 +22,7 @@ const openAddon = async page => {
) )
) { ) {
try { try {
await page.click('div[data-accountrecovery]'); await page.click('li:nth-child(3)');
await page.waitForTimeout(6000); await page.waitForTimeout(6000);
} catch { } catch {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
+37 -28
View File
@@ -8,8 +8,8 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const GasPlugin = require('gas-webpack-plugin'); const GasPlugin = require('gas-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin'); const HtmlWebpackInlineSourcePlugin = require('@effortlessmotion/html-webpack-inline-source-plugin');
const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin'); const DynamicCdnWebpackPlugin = require('@effortlessmotion/dynamic-cdn-webpack-plugin');
const moduleToCdn = require('module-to-cdn'); const moduleToCdn = require('module-to-cdn');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
@@ -25,6 +25,7 @@ envVars.NODE_ENV = process.env.NODE_ENV;
envVars.PORT = PORT; envVars.PORT = PORT;
const isProd = process.env.NODE_ENV === 'production'; const isProd = process.env.NODE_ENV === 'production';
const publicPath = process.env.ASSET_PATH || '/';
/********************************* /*********************************
* define entrypoints * define entrypoints
@@ -80,6 +81,7 @@ const copyFilesConfig = {
entry: copyAppscriptEntry, entry: copyAppscriptEntry,
output: { output: {
path: destination, path: destination,
publicPath,
}, },
plugins: [ plugins: [
new CopyWebpackPlugin({ new CopyWebpackPlugin({
@@ -107,12 +109,19 @@ const clientConfig = ({ isDevClientWrapper }) => ({
// this file will get added to the html template inline // this file will get added to the html template inline
// and should be put in .claspignore so it is not pushed // and should be put in .claspignore so it is not pushed
filename: 'main.js', filename: 'main.js',
publicPath,
}, },
resolve: { resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
}, },
module: { module: {
rules: [ rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
// typescript config // typescript config
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
@@ -174,11 +183,6 @@ const DynamicCdnWebpackPluginConfig = {
return null; return null;
} }
// return defaults if Dynamic CDN plugin finds package
if (moduleDetails) {
return moduleDetails;
}
// define custom CDN configuration for new packages // define custom CDN configuration for new packages
// "name" should match the package being imported // "name" should match the package being imported
// "var" is important to get right -- this should be the exposed global. Look up "webpack externals" for info. // "var" is important to get right -- this should be the exposed global. Look up "webpack externals" for info.
@@ -197,21 +201,29 @@ const DynamicCdnWebpackPluginConfig = {
version: packageVersion, version: packageVersion,
url: `https://unpkg.com/react-bootstrap@${packageVersion}/dist/react-bootstrap${packageSuffix}`, url: `https://unpkg.com/react-bootstrap@${packageVersion}/dist/react-bootstrap${packageSuffix}`,
}; };
// must include peer dependencies for any custom imports
case '@types/react':
return {
name: packageName,
var: '@types/react',
version: packageVersion,
url: `https://unpkg.com/@types/react@${packageVersion}/index.d.ts`,
};
// return defaults/null depending if Dynamic CDN plugin finds package
default: default:
return null; return moduleDetails;
} }
}, },
}; };
// webpack settings used by each client entrypoint defined at top // webpack settings used by each client entrypoint defined at top
const clientConfigs = clientEntrypoints.map(clientEntrypoint => { const clientConfigs = clientEntrypoints.map((clientEntrypoint) => {
const isDevClientWrapper = false; const isDevClientWrapper = false;
return { return {
...clientConfig({ isDevClientWrapper }), ...clientConfig({ isDevClientWrapper }),
name: clientEntrypoint.name, name: clientEntrypoint.name,
entry: clientEntrypoint.entry, entry: clientEntrypoint.entry,
plugins: [ plugins: [
!isProd && new webpack.HotModuleReplacementPlugin(),
!isProd && new ReactRefreshWebpackPlugin(), !isProd && new ReactRefreshWebpackPlugin(),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': JSON.stringify(envVars), 'process.env': JSON.stringify(envVars),
@@ -219,7 +231,9 @@ const clientConfigs = clientEntrypoints.map(clientEntrypoint => {
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: clientEntrypoint.template, template: clientEntrypoint.template,
filename: `${clientEntrypoint.filename}${isProd ? '' : '-impl'}.html`, filename: `${clientEntrypoint.filename}${isProd ? '' : '-impl'}.html`,
inlineSource: '^[^(//)]+.(js|css)$', // embed all js and css inline, exclude packages with '//' for dynamic cdn insertion inlineSource: '^/.*(js|css)$', // embed all js and css inline, exclude packages from dynamic cdn insertion
scriptLoading: 'blocking',
inject: 'body',
}), }),
// add the generated js code to the html file inline // add the generated js code to the html file inline
new HtmlWebpackInlineSourcePlugin(), new HtmlWebpackInlineSourcePlugin(),
@@ -233,14 +247,14 @@ const clientConfigs = clientEntrypoints.map(clientEntrypoint => {
const devServer = { const devServer = {
hot: true, hot: true,
port: PORT, port: PORT,
https: true, server: 'https',
}; };
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) { if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
// use key and cert settings only if they are found // use key and cert settings only if they are found
devServer.https = { devServer.server = {
key: fs.readFileSync(keyPath), type: 'https',
cert: fs.readFileSync(certPath), options: { key: fs.readFileSync(keyPath), cert: fs.readFileSync(certPath) },
}; };
} }
@@ -248,14 +262,14 @@ if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
// script at test/generate-cert.ps1 can be used to create a .pfx cert // script at test/generate-cert.ps1 can be used to create a .pfx cert
if (fs.existsSync(pfxPath)) { if (fs.existsSync(pfxPath)) {
// use pfx file if it's found // use pfx file if it's found
devServer.https = { devServer.server = {
pfx: fs.readFileSync(pfxPath), type: 'https',
passphrase: 'abc123', options: { pfx: fs.readFileSync(pfxPath), passphrase: 'abc123' },
}; };
} }
// webpack settings for the development client wrapper // webpack settings for the development client wrapper
const devClientConfigs = clientEntrypoints.map(clientEntrypoint => { const devClientConfigs = clientEntrypoints.map((clientEntrypoint) => {
envVars.FILENAME = clientEntrypoint.filename; envVars.FILENAME = clientEntrypoint.filename;
const isDevClientWrapper = true; const isDevClientWrapper = true;
return { return {
@@ -270,7 +284,9 @@ const devClientConfigs = clientEntrypoints.map(clientEntrypoint => {
template: './dev/index.html', template: './dev/index.html',
// this should match the html files we load in src/server/ui.js // this should match the html files we load in src/server/ui.js
filename: `${clientEntrypoint.filename}.html`, filename: `${clientEntrypoint.filename}.html`,
inlineSource: '^[^(//)]+.(js|css)$', // embed all js and css inline, exclude packages with '//' for dynamic cdn insertion inlineSource: '^/.*(js|css)$', // embed all js and css inline, exclude packages from dynamic cdn insertion
scriptLoading: 'blocking',
inject: 'body',
}), }),
new HtmlWebpackInlineSourcePlugin(), new HtmlWebpackInlineSourcePlugin(),
new DynamicCdnWebpackPlugin({}), new DynamicCdnWebpackPlugin({}),
@@ -290,6 +306,7 @@ const serverConfig = {
filename: 'code.js', filename: 'code.js',
path: destination, path: destination,
libraryTarget: 'this', libraryTarget: 'this',
publicPath,
}, },
resolve: { resolve: {
extensions: ['.ts', '.js', '.json'], extensions: ['.ts', '.js', '.json'],
@@ -322,7 +339,6 @@ const serverConfig = {
minimize: true, minimize: true,
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({
sourceMap: true,
terserOptions: { terserOptions: {
// ecma 5 is needed to support Rhino "DEPRECATED_ES5" runtime // ecma 5 is needed to support Rhino "DEPRECATED_ES5" runtime
// can use ecma 6 if V8 runtime is used // can use ecma 6 if V8 runtime is used
@@ -345,13 +361,6 @@ const serverConfig = {
], ],
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({
// replace any env variables in client-side code like PORT and NODE_ENV with actual values
'process.env': JSON.stringify(envVars),
'process.env.NODE_ENV': JSON.stringify(
isProd ? 'production' : 'development'
),
}),
new GasPlugin({ new GasPlugin({
// removes need for assigning public server functions to "global" // removes need for assigning public server functions to "global"
autoGlobalExportsFiles: [serverEntry], autoGlobalExportsFiles: [serverEntry],