Skip to content

Commit

Permalink
[LEOP-287]Apply all customize features to CRA5-Part2 (#145)
Browse files Browse the repository at this point in the history
* Update paths/depencies/readme and changelog

* Update config file and custom config

* Update scripts files and related other files

* Update lock file

* perfect some annotation

* Add comments

* add some comments and remove cache-loader

* remove writeToDisk configration

* Remove extra space from the end line

* remove cache-loader config and comment

* Add nackpack-addons comment and restore code

* Update version and changelog

* Update packages/react-scripts/package.json

Co-authored-by: Jayson Wu <jaysonwu991@outlook.com>

Co-authored-by: Jayson Wu <jaysonwu991@outlook.com>
  • Loading branch information
salleyliu and jaysonwu991 authored Apr 27, 2022
1 parent e966830 commit 71ee671
Show file tree
Hide file tree
Showing 15 changed files with 3,497 additions and 555 deletions.
2,391 changes: 1,933 additions & 458 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions packages/react-scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# `backpack-react-scripts` Change Log

## 11.0.0

### Breaking

- Rebased onto `upstream/master` v5.0.0 (9673858a3715287c40aef9e800c431c7d45c05a2).
- This release rebases `backpack-react-scripts` on top of `create-react-app` v5! The major changes have been summarised in the following blog post:
[Create React App 5.0](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md#500-2021-12-14)

### Changed

Remove `cache-loader` and related configration(`cache-loader` is not suggested in creact-react-app v5)

## 10.0.1

- Extract the existing custom features from the BRS fork branch
- Extract custom `ssr` features into backpack-addons folder

## 10.0.0

### Features
Expand Down
38 changes: 33 additions & 5 deletions packages/react-scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
# react-scripts
# backpack-react-scripts

This package includes scripts and configuration used by [Create React App](https://github.com/facebook/create-react-app).<br>
Please refer to its documentation:
### **Important:** The currently supported version of **CRA** by `backpack-react-scripts` is up to `v5+`. Versions above this may not work.

- [Getting Started](https://facebook.github.io/create-react-app/docs/getting-started) – How to create a new app.
- [User Guide](https://facebook.github.io/create-react-app/) – How to develop apps bootstrapped with Create React App.
This package is a fork of [Create React App](https://github.com/facebookincubator/create-react-app) (specifically the
`react-scripts` package). It's intended to be used in conjuction with `create-react-app` like so:

```sh
npx create-react-app my-app --scripts-version=@skyscanner/backpack-react-scripts --template @skyscanner/backpack --use-npm

# start your app development like you normally would with `create-react-app`
cd my-app
npm start
```

## What is different in our fork?

- Compilation of uncompiled Backpack components (specifically JSX).
- Skyscanner specific template with Backpack components integrated out of the box. Published as `@skyscanner/cra-template-backpack`
- CSS Modules enabled by default for all `.css` & `.scss` files.
- Ability to create a bundle for server side rending.
- Automatic chunking is disabled by default.
- **`css.html` & `js.html`**: New files in the `build/` output folder. These are html partials that include `<script />` and `<link />` references to the various static assets output by webpack. Useful if automatic chunking is turned on and you don't want to worry about order.
- A bunch of configuration options via `"backpack-react-scripts"` field in `package.json`:
- `crossOriginLoading`: Modify the default behaviour, see [docs](https://webpack.js.org/configuration/output/#output-crossoriginloading).
- `babelIncludePrefixes`: An array of module name prefixes to opt into babel compilation. Includes `["@skyscanner/bpk-", "bpk-", "saddlebag-"]` by default.
- `enableAutomaticChunking`: Boolean, opt in to automatic chunking of vendor, common and app code.
- `vendorsChunkRegex`: String, Regex for picking what goes into the `vendors` chunk. See `cacheGroups` in webpack docs. Dependent on `enableAutomaticChunking` being enabled
- `amdExcludes`: Array of module names to exclude from AMD parsing. Incldues `["lodash"]` by default.
- `externals`: exposing the Webpack config to modify externals, see [docs](https://webpack.js.org/configuration/externals/).
- `ssrExternals`: Similar to above, but for `ssr.js` only.
- `cssModules`: Boolean, true by default.
- `sriEnabled`: Sets if SRI is to be used during build to add integrity hash for files, see [docs](https://github.com/waysact/webpack-subresource-integrity/blob/master/README.md).
- **Note** if this is enabled, `crossOriginLoading` value is overriden with `anonymous` in order for it to output with the integrity value.
- `ignoreCssWarnings`: Boolean, false by default. Allows the ability to supress CSS ordering issues when its safe to allow mixed order when it has not effect on output, see [docs](https://github.com/webpack-contrib/mini-css-extract-plugin#remove-order-warnings). False by default
18 changes: 15 additions & 3 deletions packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@ const spawn = require('react-dev-utils/crossSpawn');
const args = process.argv.slice(2);

const scriptIndex = args.findIndex(
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
x =>
x === 'build' ||
x === 'build-ssr' ||
x === 'eject' ||
x === 'start' ||
x === 'start-ssr' ||
x === 'test'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];

if (['build', 'eject', 'start', 'test'].includes(script)) {
if (
['build', 'build-ssr', 'eject', 'start', 'start-ssr', 'test'].includes(script)
) {
const result = spawn.sync(
process.execPath,
nodeArgs
.concat(require.resolve('../scripts/' + script))
.concat(
require.resolve(
`../scripts/${script === 'build-ssr' ? 'build' : script}`
)
)
.concat(args.slice(scriptIndex + 1)),
{ stdio: 'inherit' }
);
Expand Down
9 changes: 4 additions & 5 deletions packages/react-scripts/config/css.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% _.each(htmlWebpackPlugin.files.css, file => { %><link
rel="stylesheet"
href="<%= file %>"
/>
<% }); %>

rel="stylesheet"
href="<%= file %>"
/>
<% }); %>
5 changes: 2 additions & 3 deletions packages/react-scripts/config/js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<% _.each(htmlWebpackPlugin.files.js, file => { %>
<script src="<%= file %>"></script>
<% }); %>

<script src="<%= file %>"></script>
<% }); %>
11 changes: 10 additions & 1 deletion packages/react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ module.exports = {
dotenv: resolveApp('.env'),
appPath: resolveApp('.'),
appBuild: resolveApp(buildPath),
appBuildWeb: resolveApp('build/web'), // #backpack-addons
appBuildSsr: resolveApp('build/ssr'), // #backpack-addons
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
Expand All @@ -78,6 +80,7 @@ module.exports = {
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
swSrc: resolveModule(resolveApp, 'src/service-worker'),
publicUrlOrPath,
appSsrJs: resolveApp('src/ssr.js'), // #backpack-addons
};

// @remove-on-eject-begin
Expand All @@ -89,6 +92,8 @@ module.exports = {
appPath: resolveApp('.'),
appBuild: resolveApp(buildPath),
appPublic: resolveApp('public'),
appBuildWeb: resolveApp('build/web'), // #backpack-addons
appBuildSsr: resolveApp('build/ssr'), // #backpack-addons
appHtml: resolveApp('public/index.html'),
appIndexJs: resolveModule(resolveApp, 'src/index'),
appPackageJson: resolveApp('package.json'),
Expand All @@ -103,6 +108,7 @@ module.exports = {
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
swSrc: resolveModule(resolveApp, 'src/service-worker'),
publicUrlOrPath,
appSsrJs: resolveApp('src/ssr.js'), // #backpack-addons
// These properties only exist before ejecting:
ownPath: resolveOwn('.'),
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
Expand All @@ -125,7 +131,9 @@ if (
module.exports = {
dotenv: resolveOwn(`${templatePath}/.env`),
appPath: resolveApp('.'),
appBuild: resolveOwn(path.join('../..', buildPath)),
appBuild: resolveOwn(`../../${buildPath}`),
appBuildWeb: resolveOwn('../../build/web'), // #backpack-addons
appBuildSsr: resolveOwn('../../build/ssr'), // #backpack-addons
appPublic: resolveOwn(`${templatePath}/public`),
appHtml: resolveOwn(`${templatePath}/public/index.html`),
appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
Expand All @@ -141,6 +149,7 @@ if (
appTsBuildInfoFile: resolveOwn('node_modules/.cache/tsconfig.tsbuildinfo'),
swSrc: resolveModule(resolveOwn, `${templatePath}/src/service-worker`),
publicUrlOrPath,
appSsrJs: resolveOwn(`${templatePath}/src/ssr.js`), // #backpack-addons
// These properties only exist before ejecting:
ownPath: resolveOwn('.'),
ownNodeModules: resolveOwn('node_modules'),
Expand Down
Loading

0 comments on commit 71ee671

Please sign in to comment.