Skip to content

Commit 2436ee0

Browse files
committed
update to v1.0.1
1 parent 882c743 commit 2436ee0

File tree

8 files changed

+85
-49
lines changed

8 files changed

+85
-49
lines changed

config/env.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
'use strict';
1212

1313
const fs = require('fs');
14+
const path = require('path');
1415
const paths = require('./paths');
1516

17+
// Make sure that including paths.js after env.js will read .env variables.
18+
delete require.cache[require.resolve('./paths')];
19+
1620
const NODE_ENV = process.env.NODE_ENV;
1721
if (!NODE_ENV) {
1822
throw new Error(
@@ -24,9 +28,13 @@ if (!NODE_ENV) {
2428
var dotenvFiles = [
2529
`${paths.dotenv}.${NODE_ENV}.local`,
2630
`${paths.dotenv}.${NODE_ENV}`,
27-
`${paths.dotenv}.local`,
31+
// Don't include `.env.local` for `test` environment
32+
// since normally you expect tests to produce the same
33+
// results for everyone
34+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
2835
paths.dotenv,
29-
];
36+
].filter(Boolean);
37+
3038
// Load environment variables from .env* files. Suppress warnings using silent
3139
// if this file is missing. dotenv will never modify any environment variables
3240
// that have already been set.
@@ -39,6 +47,22 @@ dotenvFiles.forEach(dotenvFile => {
3947
}
4048
});
4149

50+
// We support resolving modules according to `NODE_PATH`.
51+
// This lets you use absolute paths in imports inside large monorepos:
52+
// https://github.com/facebookincubator/create-react-app/issues/253.
53+
// It works similar to `NODE_PATH` in Node itself:
54+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
55+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
56+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
57+
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
58+
// We also resolve them to make sure all tools using them work consistently.
59+
const appDirectory = fs.realpathSync(process.cwd());
60+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
61+
.split(path.delimiter)
62+
.filter(folder => folder && !path.isAbsolute(folder))
63+
.map(folder => path.resolve(appDirectory, folder))
64+
.join(path.delimiter);
65+
4266
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
4367
// injected into the application via DefinePlugin in Webpack configuration.
4468
const REACT_APP = /^REACT_APP_/i;

config/paths.js

+4-27
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,7 @@ const url = require('url');
1717
// Make sure any symlinks in the project folder are resolved:
1818
// https://github.com/facebookincubator/create-react-app/issues/637
1919
const appDirectory = fs.realpathSync(process.cwd());
20-
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
21-
22-
// We support resolving modules according to `NODE_PATH`.
23-
// This lets you use absolute paths in imports inside large monorepos:
24-
// https://github.com/facebookincubator/create-react-app/issues/253.
25-
26-
// It works similar to `NODE_PATH` in Node itself:
27-
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
28-
29-
// We will export `nodePaths` as an array of absolute paths.
30-
// It will then be used by Webpack configs.
31-
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.
32-
33-
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
34-
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
35-
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
36-
37-
const nodePaths = (process.env.NODE_PATH || '')
38-
.split(process.platform === 'win32' ? ';' : ':')
39-
.filter(Boolean)
40-
.filter(folder => !path.isAbsolute(folder))
41-
.map(resolveApp);
20+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
4221

4322
const envPublicUrl = process.env.PUBLIC_URL;
4423

@@ -53,7 +32,8 @@ function ensureSlash(path, needsSlash) {
5332
}
5433
}
5534

56-
const getPublicUrl = (appPackageJson) => envPublicUrl || require(appPackageJson).homepage;
35+
const getPublicUrl = appPackageJson =>
36+
envPublicUrl || require(appPackageJson).homepage;
5737

5838
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
5939
// "public path" at which the app is served.
@@ -80,13 +60,12 @@ module.exports = {
8060
yarnLockFile: resolveApp('yarn.lock'),
8161
testsSetup: resolveApp('src/setupTests.js'),
8262
appNodeModules: resolveApp('node_modules'),
83-
nodePaths: nodePaths,
8463
publicUrl: getPublicUrl(resolveApp('package.json')),
8564
servedPath: getServedPath(resolveApp('package.json')),
8665
};
8766

8867
// @remove-on-eject-begin
89-
const resolveOwn = (relativePath) => path.resolve(__dirname, '..', relativePath);
68+
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
9069

9170
// config before eject: we're in ./node_modules/react-scripts/config/
9271
module.exports = {
@@ -101,7 +80,6 @@ module.exports = {
10180
yarnLockFile: resolveApp('yarn.lock'),
10281
testsSetup: resolveApp('src/setupTests.js'),
10382
appNodeModules: resolveApp('node_modules'),
104-
nodePaths: nodePaths,
10583
publicUrl: getPublicUrl(resolveApp('package.json')),
10684
servedPath: getServedPath(resolveApp('package.json')),
10785
// These properties only exist before ejecting:
@@ -131,7 +109,6 @@ if (
131109
yarnLockFile: resolveOwn('template/yarn.lock'),
132110
testsSetup: resolveOwn('template/src/setupTests.js'),
133111
appNodeModules: resolveOwn('node_modules'),
134-
nodePaths: nodePaths,
135112
publicUrl: getPublicUrl(resolveOwn('package.json')),
136113
servedPath: getServedPath(resolveOwn('package.json')),
137114
// These properties only exist before ejecting:

config/webpack.config.dev.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ module.exports = {
8383
},
8484
resolve: {
8585
// This allows you to set a fallback for where Webpack should look for modules.
86-
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
8786
// We placed these paths second because we want `node_modules` to "win"
8887
// if there are any conflicts. This matches Node resolution mechanism.
8988
// https://github.com/facebookincubator/create-react-app/issues/253
90-
modules: ['node_modules', paths.appNodeModules].concat(paths.nodePaths),
89+
modules: ['node_modules', paths.appNodeModules].concat(
90+
// It is guaranteed to exist because we tweak it in `env.js`
91+
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
92+
),
9193
// These are the reasonable defaults supported by the Node ecosystem.
9294
// We also include JSX as a common component filename extension to support
9395
// some tools, although we do not recommend using it, see:

config/webpack.config.prod.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ module.exports = {
8181
},
8282
resolve: {
8383
// This allows you to set a fallback for where Webpack should look for modules.
84-
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
8584
// We placed these paths second because we want `node_modules` to "win"
8685
// if there are any conflicts. This matches Node resolution mechanism.
8786
// https://github.com/facebookincubator/create-react-app/issues/253
88-
modules: ['node_modules', paths.appNodeModules].concat(paths.nodePaths),
87+
modules: ['node_modules', paths.appNodeModules].concat(
88+
// It is guaranteed to exist because we tweak it in `env.js`
89+
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
90+
),
8991
// These are the reasonable defaults supported by the Node ecosystem.
9092
// We also include JSX as a common component filename extension to support
9193
// some tools, although we do not recommend using it, see:
@@ -321,6 +323,9 @@ module.exports = {
321323
minify: true,
322324
navigateFallback: publicUrl + '/index.html',
323325
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
326+
// Work around Windows path issue in SWPrecacheWebpackPlugin:
327+
// https://github.com/facebookincubator/create-react-app/issues/2235
328+
stripPrefix: paths.appBuild.replace(/\\/g, '/') + '/',
324329
}),
325330
// Moment.js is an extremely popular library that bundles large locale files
326331
// by default due to how Webpack interprets its code. This is a practical

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-scripts-cssmodules",
3-
"version": "1.0.0",
3+
"version": "1.0.10",
44
"description": "Configuration and scripts for Create React App - With CSS Modules",
55
"repository": "ro-savage/react-scripts-cssmodules",
66
"license": "BSD-3-Clause",
@@ -35,7 +35,7 @@
3535
"css-loader": "0.28.1",
3636
"dotenv": "4.0.0",
3737
"eslint": "3.19.0",
38-
"eslint-config-react-app": "^1.0.0",
38+
"eslint-config-react-app": "^1.0.1",
3939
"eslint-loader": "1.7.1",
4040
"eslint-plugin-flowtype": "2.33.0",
4141
"eslint-plugin-import": "2.2.0",
@@ -51,8 +51,8 @@
5151
"postcss-flexbugs-fixes": "3.0.0",
5252
"postcss-loader": "2.0.5",
5353
"promise": "7.1.1",
54-
"react-dev-utils": "^1.0.0",
55-
"react-error-overlay": "^1.0.0",
54+
"react-dev-utils": "^1.0.1",
55+
"react-error-overlay": "^1.0.1",
5656
"style-loader": "0.17.0",
5757
"sw-precache-webpack-plugin": "0.9.1",
5858
"url-loader": "0.5.8",

scripts/start.js

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ choosePort(HOST, DEFAULT_PORT)
8484
console.log(chalk.cyan('Starting the development server...\n'));
8585
openBrowser(urls.localUrlForBrowser);
8686
});
87+
88+
['SIGINT', 'SIGTERM'].forEach(function(sig) {
89+
process.on(sig, function() {
90+
devServer.close();
91+
process.exit();
92+
});
93+
});
8794
})
8895
.catch(err => {
8996
if (err && err.message) {

template/README.md

+30-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ You can find the most recent version of this guide [here](https://github.com/fac
6161
- [Disabling jsdom](#disabling-jsdom)
6262
- [Snapshot Testing](#snapshot-testing)
6363
- [Editor Integration](#editor-integration)
64+
<!--
6465
- [Developing Components in Isolation](#developing-components-in-isolation)
66+
-->
6567
- [Making a Progressive Web App](#making-a-progressive-web-app)
6668
- [Offline-First Considerations](#offline-first-considerations)
6769
- [Progressive Web App Metadata](#progressive-web-app-metadata)
@@ -470,6 +472,20 @@ Now you can rename `src/App.css` to `src/App.scss` and run `npm run watch-css`.
470472

471473
To share variables between Sass files, you can use Sass imports. For example, `src/App.scss` and other component style files could include `@import "./shared.scss";` with variable definitions.
472474

475+
To enable importing files without using relative paths, you can add the `--include-path` option to the command in `package.json`.
476+
477+
```
478+
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
479+
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
480+
```
481+
482+
This will allow you to do imports like
483+
484+
```scss
485+
@import 'styles/_colors.scss'; // assuming a styles directory under src/
486+
@import 'nprogress/nprogress'; // importing a css file from the nprogress node module
487+
```
488+
473489
At this point you might want to remove all CSS files from the source control, and add `src/**/*.css` to your `.gitignore` file. It is generally a good practice to keep the build products outside of the source control.
474490

475491
As a final step, you may find it convenient to run `watch-css` automatically with `npm start`, and run `build-css` as a part of `npm run build`. You can use the `&&` operator to execute two scripts sequentially. However, there is no cross-platform way to run two scripts in parallel, so we will install a package for this:
@@ -563,7 +579,7 @@ The `<script>` tag with the compiled code will be added to it automatically duri
563579
You can also add other assets to the `public` folder.
564580

565581
Note that we normally encourage you to `import` assets in JavaScript files instead.
566-
For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-and-fonts).
582+
For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-fonts-and-files).
567583
This mechanism provides a number of benefits:
568584

569585
* Scripts and stylesheets get minified and bundled together to avoid extra network requests.
@@ -603,7 +619,7 @@ Keep in mind the downsides of this approach:
603619

604620
### When to Use the `public` Folder
605621

606-
Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-and-fonts) from JavaScript.
622+
Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-fonts-and-files) from JavaScript.
607623
The `public` folder is useful as a workaround for a number of less common cases:
608624

609625
* You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest).
@@ -794,20 +810,20 @@ REACT_APP_SECRET_CODE=abcdef
794810

795811
`.env` files **should be** checked into source control (with the exclusion of `.env*.local`).
796812

797-
What other `.env` files are can be used?
813+
#### What other `.env` files are can be used?
798814

799-
>Note: this feature is available with `react-scripts@1.0.0` and higher.
815+
>Note: this feature is **available with `react-scripts@1.0.0` and higher**.
800816
801-
* `.env` - Default
802-
* `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
803-
* `.env.local` - Local overrides. This file is loaded for all environments except test.
804-
* `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.
817+
* `.env`: Default.
818+
* `.env.local`: Local overrides. **This file is loaded for all environments except test.**
819+
* `.env.development`, `.env.test`, `.env.production`: Environment-specific settings.
820+
* `.env.development.local`, `.env.test.local`, `.env.production.local`: Local overrides of environment-specific settings.
805821

806-
File priority, from left to right:
822+
Files on the left have more priority than files on the right:
807823

808-
* npm test - `.env.test.local`, `env.test`, `.env.local`, `.env`
809-
* npm run build - `.env.production.local`, `env.production`, `.env.local`, `.env`
810-
* npm start - `.env.development.local`, `env.development`, `.env.local`, `.env`
824+
* `npm start`: `.env.development.local`, `.env.development`, `.env.local`, `.env`
825+
* `npm run build`: `.env.production.local`, `.env.production`, `.env.local`, `.env`
826+
* `npm test`: `.env.test.local`, `.env.test`, `.env` (note `.env.local` is missing)
811827

812828
These variables will act as the defaults if the machine does not explicitly set them.<br>
813829
Please refer to the [dotenv documentation](https://github.com/motdotla/dotenv) for more details.
@@ -1282,6 +1298,7 @@ If you use [Visual Studio Code](https://code.visualstudio.com), there is a [Jest
12821298

12831299
![VS Code Jest Preview](https://cloud.githubusercontent.com/assets/49038/20795349/a032308a-b7c8-11e6-9b34-7eeac781003f.png)
12841300

1301+
<!--
12851302
## Developing Components in Isolation
12861303
12871304
Usually, in an app, you have a lot of UI components, and each of them has many different states.
@@ -1321,6 +1338,7 @@ Learn more about React Storybook:
13211338
* [GitHub Repo](https://github.com/kadirahq/react-storybook)
13221339
* [Documentation](https://storybooks.js.org/docs/react-storybook/basics/introduction/)
13231340
* [Snapshot Testing](https://github.com/kadirahq/storyshots) with React Storybook
1341+
-->
13241342

13251343
## Making a Progressive Web App
13261344

template/public/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<title>React App</title>
2323
</head>
2424
<body>
25+
<noscript>
26+
You need to enable JavaScript to run this app.
27+
</noscript>
2528
<div id="root"></div>
2629
<!--
2730
This HTML file is a template.

0 commit comments

Comments
 (0)