Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 2597583

Browse files
authored
Merge pull request #34 from Nargonath/develop
Deps and disable-chunks
2 parents 0df32ac + eae0a5e commit 2597583

File tree

6 files changed

+2033
-2924
lines changed

6 files changed

+2033
-2924
lines changed

.travis.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
stages:
2+
- test
3+
- name: deploy
4+
if: branch = master
5+
16
language: node_js
27
cache:
38
directories:
49
- ~/.npm
510
notifications:
611
email: false
712
node_js:
8-
- '9'
13+
- '12'
14+
- '10'
915
- '8'
10-
- '6'
11-
after_success:
12-
# required for yarn not to fail when installing semantic-release
13-
# instead it is removed from the dependencies and added as global at the end
14-
- yarn global add semantic-release && semantic-release || true
16+
jobs:
17+
include:
18+
- stage: deploy
19+
node_js: '12'
20+
# required for yarn not to fail when installing semantic-release
21+
# instead it is removed from the dependencies and added as global at the end
22+
script: yarn global add semantic-release && semantic-release || true
1523
branches:
1624
except:
1725
- /^v\d+\.\d+\.\d+$/

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ This tool handles ejected projects but it assumes you did not modify your `webpa
2828

2929
As of now (20/04/2018), `create-react-app` (more precisely `react-scripts`) does not allow development builds to be written to the disk because it uses `webpackDevServer` to serve your build files and folders ([for good reasons](https://github.com/facebook/create-react-app/issues/1070#issuecomment-261812303)). The problem is that in some cases you need to have these files written to the disk i.e:
3030

31-
* Developing browser extensions using React.
32-
* Incorporating your React application into an existing application.
33-
* Serving your React app with a dedicated backend.
31+
- Developing browser extensions using React.
32+
- Incorporating your React application into an existing application.
33+
- Serving your React app with a dedicated backend.
3434

3535
# Prerequisites
3636

@@ -80,9 +80,10 @@ By default the script will generate everything into `build/` at your project roo
8080

8181
If those defaults do not work for you, the script accepts some arguments:
8282

83-
* `-b|--build-path`: expects either an absolute or relative path. If a relative path is given it will be prefixed by your project root path.
84-
* default: `yourProjectRoot/build`.
85-
* `--react-scripts-version`: expects the `react-scripts` version you are using in your project i.e `2.0.3`. If not given it will be implied from your `node_modules` and if it cannot be implied the version `2.1.2` will be the default. Consider setting it if you **ejected** and are not using the latest `react-scripts` version.
86-
* `-p|--public-path`: expects a relative URL where `/` is the root. If you serve your files using an external webserver this argument is to match with your web server configuration. More information can be found in [webpack configuration guide](https://webpack.js.org/configuration/output/#output-publicpath).
87-
* default: "".
88-
* `-v|--verbose`: display webpack build output.
83+
- `-b|--build-path`: expects either an absolute or relative path. If a relative path is given it will be prefixed by your project root path.
84+
- default: `yourProjectRoot/build`.
85+
- `--disable-chunks`: disable code-splitting / chunks so that only a single bundle.js file is generated. It only works with `react-scripts` >= `2.0.0`.
86+
- `--react-scripts-version`: expects the `react-scripts` version you are using in your project i.e `2.0.3`. If not given it will be implied from your `node_modules` and if it cannot be implied the version `2.1.2` will be the default. Consider setting it if you **ejected** and are not using the latest `react-scripts` version.
87+
- `-p|--public-path`: expects a relative URL where `/` is the root. If you serve your files using an external webserver this argument is to match with your web server configuration. More information can be found in [webpack configuration guide](https://webpack.js.org/configuration/output/#output-publicpath).
88+
- default: "".
89+
- `-v|--verbose`: display webpack build output.

package.json

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,36 @@
44
"description": "A script for create-react-app that writes development builds to the disk",
55
"main": "scripts/index.js",
66
"bin": "bin/cra-build-watch.js",
7-
"files": ["bin", "scripts", "utils"],
7+
"files": [
8+
"bin",
9+
"scripts",
10+
"utils"
11+
],
812
"engines": {
913
"node": ">=6.0.0"
1014
},
1115
"scripts": {
1216
"test": "jest",
1317
"cm": "git-cz",
14-
"commitmsg": "commitlint -e",
15-
"precommit": "lint-staged",
1618
"travis-deploy-once": "travis-deploy-once",
1719
"semantic-release": "semantic-release"
1820
},
21+
"husky": {
22+
"hooks": {
23+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
24+
"pre-commit": "lint-staged"
25+
}
26+
},
1927
"config": {
2028
"commitizen": {
2129
"path": "cz-conventional-changelog"
2230
}
2331
},
2432
"lint-staged": {
25-
"{{bin,scripts,utils}/**/*.{js,json},*.{js,json}}": ["prettier --write", "git add"]
33+
"{{bin,scripts,utils}/**/*.{js,json},*.{js,json}}": [
34+
"prettier --write",
35+
"git add"
36+
]
2637
},
2738
"prettier": {
2839
"printWidth": 100,
@@ -51,25 +62,24 @@
5162
"react-scripts": ">= 1.0.x"
5263
},
5364
"devDependencies": {
54-
"@commitlint/cli": "6.1.3",
55-
"@commitlint/config-conventional": "6.1.3",
65+
"@commitlint/cli": "7.6.0",
66+
"@commitlint/config-conventional": "7.6.0",
5667
"@dixeed/eslint-config": "2.0.0",
57-
"commitizen": "2.9.6",
68+
"commitizen": "3.1.1",
5869
"cz-conventional-changelog": "2.1.0",
59-
"eslint": "4.19.1",
60-
"husky": "0.14.3",
61-
"jest": "22.4.3",
62-
"lint-staged": "7.0.4",
63-
"prettier": "1.12.1",
64-
"travis-deploy-once": "^4.4.1"
70+
"eslint": "5.16.0",
71+
"husky": "2.2.0",
72+
"jest": "^24.8.0",
73+
"lint-staged": "8.1.6",
74+
"prettier": "1.17.0"
6575
},
6676
"dependencies": {
6777
"cross-spawn": "6.0.5",
68-
"fs-extra": "5.0.0",
78+
"fs-extra": "^8.1.0",
6979
"html-webpack-plugin": "^3.2.0",
70-
"import-cwd": "2.1.0",
71-
"meow": "4.0.0",
72-
"ora": "2.0.0",
73-
"semver": "^5.6.0"
80+
"import-cwd": "3.0.0",
81+
"meow": "5.0.0",
82+
"ora": "3.4.0",
83+
"semver": "^6.3.0"
7484
}
7585
}

scripts/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ const importCwd = require('import-cwd');
66
const fs = require('fs-extra');
77
const path = require('path');
88
const ora = require('ora');
9+
const assert = require('assert');
910

1011
const {
11-
flags: { buildPath, publicPath, reactScriptsVersion, verbose },
12+
flags: { buildPath, publicPath, reactScriptsVersion, verbose, disableChunks },
1213
} = require('../utils/cliHandler');
1314
const { getReactScriptsVersion, isEjected } = require('../utils');
1415

@@ -23,8 +24,8 @@ const config =
2324
? importCwd('./config/webpack.config')
2425
: importCwd('react-scripts/config/webpack.config'))('development')
2526
: isEjected
26-
? importCwd('./config/webpack.config.dev')
27-
: importCwd('react-scripts/config/webpack.config.dev');
27+
? importCwd('./config/webpack.config.dev')
28+
: importCwd('react-scripts/config/webpack.config.dev');
2829

2930
const HtmlWebpackPlugin = importCwd('html-webpack-plugin');
3031
const InterpolateHtmlPlugin = importCwd('react-dev-utils/InterpolateHtmlPlugin');
@@ -59,6 +60,18 @@ config.output.publicPath = publicPath || '';
5960
config.output.filename = `js/bundle.js`;
6061
config.output.chunkFilename = `js/[name].chunk.js`;
6162

63+
if (disableChunks) {
64+
assert(major >= 2, 'Split chunks optimization is only available in react-scripts >= 2.0.0');
65+
// disable code-splitting/chunks
66+
config.optimization.runtimeChunk = false;
67+
68+
config.optimization.splitChunks = {
69+
cacheGroups: {
70+
default: false,
71+
},
72+
};
73+
}
74+
6275
// update media path destination
6376
if (major >= 2) {
6477
// 2.0.0 => 2
@@ -95,8 +108,7 @@ spinner.start('Clear destination folder');
95108

96109
let inProgress = false;
97110

98-
fs
99-
.emptyDir(paths.appBuild)
111+
fs.emptyDir(paths.appBuild)
100112
.then(() => {
101113
spinner.succeed();
102114

utils/cliHandler.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ module.exports = meow(
1010
Options
1111
-b, --build-path Path to the build folder. Absolute or relative path, if relative will be prefixed with project root folder path.
1212
13+
--disable-chunks Disable code-splitting / chunks so that only a single bundle.js file is generated. Only available in react-scripts >= 2.0.0.
14+
1315
-p, --public-path Public URL.
1416
1517
--react-scripts-version Version of the react-scripts package used in your project i.e 2.0.3. If not given it will be implied from your package.json and if it cannot be implied the major version 2 will be the default.
1618
1719
-v, --verbose
18-
20+
1921
Examples
2022
$ cra-build-watch -b dist/ -p /assets
2123
`,
@@ -36,6 +38,9 @@ module.exports = meow(
3638
type: 'boolean',
3739
alias: 'v',
3840
},
41+
'disable-chunks': {
42+
type: 'boolean',
43+
},
3944
},
4045
}
4146
);

0 commit comments

Comments
 (0)