Skip to content

Commit 5c29588

Browse files
authored
Merge pull request #82 from CodingZeal/chores/update-to-cra-1.0-scripts
Update to latest zeal/react-scripts
2 parents 2f7f7c9 + d0796da commit 5c29588

File tree

8 files changed

+1396
-828
lines changed

8 files changed

+1396
-828
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ ReactGen is built on [@zeal/react-scripts](https://github.com/CodingZeal/create-
6666

6767
After generating your application, you can run it using `yarn start` (or `npm start`) and you can develop on `localhost:3000` if you are not in the context of a larger framework.
6868

69+
If you are in the context of a larger framework, you can customize the `APP_PORT` variable in `.env.development` to match the port where the host application runs. You can then develop in the context of that application instead.
70+
6971
Other provided `yarn`/`npm` scripts include:
7072

7173
- `build`: Create a production-ready client bundle. By default, the bundle is placed in the `build` folder, but you can change that by setting the `BUILD_PATH` environment variable.

app/__tests__/app-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ describe("react-zeal", () => {
2626
});
2727

2828
test("copies .eslintrc.js file", () => {
29-
assert.fileContent(".eslintrc.js", "path.resolve");
29+
assert.fileContent(".eslintrc.js", "paths.appSrc");
3030
});
3131
});

app/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ module.exports = class ReactZeal extends Generator {
2525
globOptions: { dot: true }
2626
});
2727

28+
this.fs.copy(this.templatePath(".env"), this.destinationPath(".env"));
29+
this.fs.copy(
30+
this.templatePath(".env.development"),
31+
this.destinationPath(".env.development")
32+
);
33+
2834
this.fs.copy(
2935
this.templatePath(".eslintrc.js"),
3036
this.destinationPath(".eslintrc.js")

app/templates/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NODE_PATH = ./client

app/templates/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_PORT = 3000

app/templates/.eslintrc.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
const path = require("path");
1+
// Ideally, we'd point the import resolver to
2+
// `node_modules/@zeal/react-scripts/config/webpack.config.dev.js` instead of
3+
// having our own configuration here. However, that doesn't currently work:
4+
//
5+
// - @zeal/react-scripts `lint` script loads `config/env.js`, which reads the
6+
// `.env` files and then transforms the NODE_PATH by removing any absolute
7+
// paths (to avoid accidentally importing files from outside the project)
8+
// and then resolving relative paths so that they become absolute.
9+
//
10+
// - `lint` spawns a call to `eslint` which ultimately loads
11+
// `webpack.config.dev.js`. This new process inherits the massaged NODE_PATH
12+
// from above.
13+
//
14+
// - `webpack.config.dev.js` imports `config/env.js`. Since this is now a
15+
// different process, that file is reloaded which. It reloads our `.env`
16+
// file, but since dotenv ["will never modify any environment variables that
17+
// have already been set"](https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set),
18+
// the now-absolute NODE_PATH entry gets removed during the NODE_PATH
19+
// transformation.
20+
//
21+
// - As a result, `eslint` can't properly resolve any of our module imports.
22+
//
23+
24+
const paths = require("@zeal/react-scripts/config/paths");
225

326
module.exports = {
427
extends: ["zeal", "zeal/react", "prettier", "prettier/react"],
@@ -8,7 +31,7 @@ module.exports = {
831
webpack: {
932
config: {
1033
resolve: {
11-
root: path.resolve(__dirname, "client")
34+
modules: [paths.ownNodeModules, paths.appNodeModules, paths.appSrc]
1235
}
1336
}
1437
}

app/templates/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@zeal/react-scripts": "^1.0.0",
6+
"@zeal/react-scripts": "^2.0.0",
77
"babel-polyfill": "^6.23.0",
88
"enzyme": "^2.8.2",
9+
"eslint": "3.19.0",
910
"eslint-config-prettier": "^2.1.1",
1011
"history": "^4.6.1",
1112
"husky": "^0.13.3",

0 commit comments

Comments
 (0)