Skip to content

Commit d444567

Browse files
committed
Rebase with latest CRA version
1 parent 9b3e842 commit d444567

15 files changed

+204
-367
lines changed

config/polyfills.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ require("whatwg-fetch");
1414
// Object.assign() is commonly used with React.
1515
// It will use the native implementation if it's present and isn't buggy.
1616
Object.assign = require("object-assign");
17+
18+
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
19+
// We don't polyfill it in the browser--this is user's responsibility.
20+
if (process.env.NODE_ENV === "test") {
21+
require("raf").polyfill(global);
22+
}

config/webpack/build-env.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/webpack/config.common.js

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
1111

1212
const paths = require("../paths");
1313
const loadingAnimation = require("../../src/generated/loading.scss.json");
14-
const webpackEnv = require("./build-env");
1514

1615
/*
1716
Define various constants to be used in multiple different configs here.
@@ -190,25 +189,14 @@ const RULE_WEBFONTS = function() {
190189
// "file" loader makes sure those assets get served by WebpackDevServer.
191190
// When you `import` an asset, you get its (virtual) filename.
192191
// In production, they would get copied to the `build` folder.
192+
// This loader doesn't use a "test" so it will catch all modules
193+
// that fall through the other loaders.
193194
const RULE_COVER_NON_MATCHED = {
194-
exclude: [
195-
/\.html$/,
196-
// We have to write /\.(js|jsx)(\?.*)?$/ rather than just /\.(js|jsx)$/
197-
// because you might change the hot reloading server from the custom one
198-
// to Webpack's built-in webpack-dev-server/client?/, which would not
199-
// get properly excluded by /\.(js|jsx)$/ because of the query string.
200-
// Webpack 2 fixes this, but for now we include this hack.
201-
// https://github.com/facebookincubator/create-react-app/issues/1713
202-
/\.(js|jsx)(\?.*)?$/,
203-
/\.(ts|tsx)(\?.*)?$/,
204-
/\.s?css$/,
205-
/\.json$/,
206-
/\.bmp$/,
207-
/\.gif$/,
208-
/\.jpe?g$/,
209-
/\.png$/,
210-
/\.(ttf|eot|svg|woff|woff2)/
211-
],
195+
// Exclude `js` files to keep "css" loader working as it injects
196+
// it's runtime that would otherwise processed through "file" loader.
197+
// Also exclude `html` and `json` extensions so they get processed
198+
// by webpacks internal loaders.
199+
exclude: [/\.js$/, /\.html$/, /\.json$/],
212200
loader: require.resolve("file-loader"),
213201
options: {
214202
name: "static/media/[name].[hash:8].[ext]"
@@ -245,6 +233,7 @@ const resolveOptions = {
245233
};
246234

247235
const nodeOptions = {
236+
dgram: "empty",
248237
fs: "empty",
249238
net: "empty",
250239
tls: "empty",
@@ -284,18 +273,19 @@ module.exports = function(isDev, env, extractTextPluginOptions) {
284273
// TODO: Disable require.ensure as it's not a standard language feature.
285274
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
286275
// { parser: { requireEnsure: false } },
287-
RULE_EXT_JS,
288-
// ** ADDING/UPDATING LOADERS **
289-
// The "file" loader handles all assets unless explicitly excluded.
290-
// The `exclude` list *must* be updated with every change to loader extensions.
291-
// When adding a new loader, you must add its `test`
292-
// as a new entry in the `exclude` list in the "file" loader.
293-
294-
RULE_COVER_NON_MATCHED,
295-
RULE_IMAGES,
296-
RULE_EXT_TSX(isDev),
297-
RULE_SCSS(isDev, extractTextPluginOptions),
298-
RULE_WEBFONTS()
276+
{
277+
// "oneOf" will traverse all following loaders until one will
278+
// match the requirements. When no loader matches it will fall
279+
// back to the "file" loader at the end of the loader list.
280+
oneOf: [
281+
RULE_EXT_JS,
282+
RULE_EXT_TSX(isDev),
283+
RULE_IMAGES,
284+
RULE_SCSS(isDev, extractTextPluginOptions),
285+
RULE_WEBFONTS(),
286+
RULE_COVER_NON_MATCHED
287+
]
288+
}
299289
// ** STOP ** Are you adding a new loader?
300290
// Remember to add the new extension(s) to the "file" loader exclusion list.
301291
]

config/webpack/config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = merge.smart(commonConfig(true, env, {}), {
6666
chunkFilename: "static/js/[name].chunk.js",
6767
// This is the URL that app is served from. We use "/" in development.
6868
publicPath: publicPath,
69-
// Point sourcemap entries to original disk location
69+
// Point sourcemap entries to original disk location (format as URL on Windows)
7070
devtoolModuleFilenameTemplate: info =>
7171
path.resolve(info.absoluteResourcePath).replace(/\\/g, "/")
7272
},

config/webpack/config.prod.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ const ExtractTextPlugin = require("extract-text-webpack-plugin");
1111
const InlineChunkManifestHtmlWebpackPlugin = require("inline-chunk-manifest-html-webpack-plugin");
1212
const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin");
1313
const merge = require("webpack-merge");
14-
const ClosureCompilerPlugin = require("webpack-closure-compiler");
1514
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
1615
.BundleAnalyzerPlugin;
1716

1817
const commonConfig = require("./config.common");
1918
const paths = require("../paths");
2019
const getClientEnvironment = require("../env");
21-
const webpackEnv = require("./build-env");
2220

2321
// Webpack uses `publicPath` to determine where the app is being served from.
2422
// It requires a trailing slash, or the file assets will get an incorrect path.
2523
const publicPath = paths.servedPath;
2624
// Some apps do not use client-side routing with pushState.
2725
// For these, "homepage" can be set to "." to enable relative asset paths.
2826
const shouldUseRelativeAssetPaths = publicPath === "./";
27+
// Source maps are resource heavy and can cause out of memory issue for large source files.
28+
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false";
2929
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3030
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3131
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
@@ -51,32 +51,6 @@ const extractTextPluginOptions = shouldUseRelativeAssetPaths
5151
{ publicPath: Array(cssFilename.split("/").length).join("../") }
5252
: {};
5353

54-
// Determine minifier. Note that without its 'ADVANCED' mode, the closure compiler does
55-
// necessarily generate smaller results. Although - in most cases - the results ARE smaller
56-
// than with UglifyJs, at least several KB. However, it also takes longer to build.
57-
const minifier = webpackEnv.useClosureCompiler
58-
? new ClosureCompilerPlugin({
59-
compiler: {
60-
language_in: "ECMASCRIPT5",
61-
language_out: "ECMASCRIPT5"
62-
// Note: compilation_level: 'ADVANCED' does not work (yet?).
63-
},
64-
concurrency: 3
65-
})
66-
: new UglifyJsPlugin({
67-
compress: {
68-
warnings: false,
69-
// This feature has been reported as buggy a few times, such as:
70-
// https://github.com/mishoo/UglifyJS2/issues/1964
71-
// We'll wait with enabling it by default until it is more solid.
72-
reduce_vars: false
73-
},
74-
output: {
75-
comments: false
76-
},
77-
sourceMap: true
78-
});
79-
8054
// This is the production configuration.
8155
// It compiles slowly and is focused on producing a fast and minimal bundle.
8256
// The development configuration is different and lives in a separate file.
@@ -87,7 +61,7 @@ module.exports = merge.smart(
8761
bail: true,
8862
// We generate sourcemaps in production. This is slow but gives good results.
8963
// You can exclude the *.map files from the build during deployment.
90-
devtool: "source-map",
64+
devtool: shouldUseSourceMap ? "source-map" : false,
9165
// In production, we only want to load the polyfills and the app code.
9266
entry: [require.resolve("../polyfills"), paths.appIndexJs],
9367
output: {
@@ -102,7 +76,9 @@ module.exports = merge.smart(
10276
publicPath: publicPath,
10377
// Point sourcemap entries to original disk location
10478
devtoolModuleFilenameTemplate: info =>
105-
path.relative(paths.appSrc, info.absoluteResourcePath)
79+
path
80+
.relative(paths.appSrc, info.absoluteResourcePath)
81+
.replace(/\\/g, "/")
10682
},
10783

10884
plugins: [
@@ -130,10 +106,25 @@ module.exports = merge.smart(
130106

131107
// EO
132108

133-
// Plugin to let the whole build fail on any error; i.e. do not tolerate these
109+
// Plugin to let the whole build fail on any error; i.e. do not tolerate these/
134110
new NoEmitOnErrorsPlugin(),
135111
// Minify the code.
136-
minifier,
112+
new UglifyJsPlugin({
113+
compress: {
114+
warnings: false,
115+
// This feature has been reported as buggy a few times, such as:
116+
// https://github.com/mishoo/UglifyJS2/issues/1964
117+
// We'll wait with enabling it by default until it is more solid.
118+
reduce_vars: false
119+
},
120+
output: {
121+
comments: false,
122+
// Turned on because emoji and regex is not minified properly using default
123+
// https://github.com/facebookincubator/create-react-app/issues/2488
124+
ascii_only: true
125+
},
126+
sourceMap: true
127+
}),
137128
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
138129
new ExtractTextPlugin({
139130
filename: cssFilename

config/webpack/dev-server.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const errorOverlayMiddleware = require("react-dev-utils/errorOverlayMiddleware");
44
const noopServiceWorkerMiddleware = require("react-dev-utils/noopServiceWorkerMiddleware");
55

6+
const path = require("path");
67
const config = require("./config.dev");
78
const paths = require("../paths");
89

@@ -65,8 +66,15 @@ module.exports = function(proxy, allowedHost) {
6566
quiet: true,
6667
// Reportedly, this avoids CPU overload on some systems.
6768
// https://github.com/facebookincubator/create-react-app/issues/293
69+
// src/node_modules is not ignored to support absolute imports
70+
// https://github.com/facebookincubator/create-react-app/issues/1065
6871
watchOptions: {
69-
ignored: /node_modules/
72+
ignored: new RegExp(
73+
`^(?!${path
74+
.normalize(paths.appSrc + "/")
75+
.replace(/[\\]+/g, "\\\\")}).+[\\\\/]node_modules[\\\\/]`,
76+
"g"
77+
)
7078
},
7179
// Enable HTTPS if the HTTPS environment variable is set to 'true'
7280
https: protocol === "https",

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
"transform": {
3131
"^.+\\.s?css$": "<rootDir>/config/jest/cssTransform.js",
3232
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js",
33-
"^(?!.*\\.(css|json)$)": "<rootDir>/config/jest/fileTransform.js"
33+
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
3434
},
3535
"transformIgnorePatterns": [
3636
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$"

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"postcss-loader": "^2.0.7",
6363
"prettier": "^1.8.2",
6464
"promise": "^8.0.1",
65+
"raf": "^3.4.0",
6566
"react-dev-utils": "^4.2.1",
6667
"react-error-overlay": "^3.0.0",
6768
"react-hot-loader": "3.1.2",
@@ -87,7 +88,6 @@
8788
"webpack": "^3.8.1",
8889
"webpack-bundle-analyzer": "^2.9.1",
8990
"webpack-chunk-hash": "^0.5.0",
90-
"webpack-closure-compiler": "^2.1.5",
9191
"webpack-dev-server": "^2.9.4",
9292
"webpack-manifest-plugin": "^1.3.2",
9393
"webpack-merge": "^4.1.1",
@@ -106,8 +106,6 @@
106106
"format": "prettier --write \"{src,scripts,config}/**/*.{js,ts,tsx}\"",
107107
"precommit": "lint-staged",
108108
"prepush": "npm run test:ci",
109-
"-----need to translate these scripts!-----": "echo 0",
110-
"clear": "rimraf .awcache .tmp .dist src/generated",
111109
"translations": "node scripts/translations/compile-translations.js \"src/**/*.i18n.yml\" src/generated/translations.ts"
112110
},
113111
"lint-staged": {
@@ -117,8 +115,8 @@
117115
]
118116
},
119117
"engines": {
120-
"node": ">=6.9",
121-
"npm": ">=3.10",
122-
"yarn": ">=0.20.0"
118+
"node": ">=8.9",
119+
"npm": ">=5.10",
120+
"yarn": ">=1.0.0"
123121
}
124122
}

public/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"icons": [
55
{
66
"src": "favicon.ico",
7-
"sizes": "192x192",
8-
"type": "image/png"
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
99
}
1010
],
1111
"start_url": "./index.html",

scripts/build.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ measureFileSizesBeforeBuild(paths.appBuild)
9494
},
9595
err => {
9696
console.log(chalk.red("Failed to compile.\n"));
97-
console.log((err.message || err) + "\n");
97+
printBuildError(err);
9898
process.exit(1);
9999
}
100100
);
@@ -111,6 +111,12 @@ function build(previousFileSizes) {
111111
}
112112
const messages = formatWebpackMessages(stats.toJson({}, true));
113113
if (messages.errors.length) {
114+
// TODO: Disabled for the moment, esp. because of TS errors.
115+
// Only keep the first error. Others are often indicative
116+
// of the same problem, but confuse the reader with noise.
117+
// if (messages.errors.length > 1) {
118+
// messages.errors.length = 1;
119+
//}
114120
return reject(new Error(messages.errors.join("\n\n")));
115121
}
116122
if (

scripts/start.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
22

3+
process.env.NODE_ENV = "development";
4+
35
// Makes the script crash on unhandled rejections instead of silently
46
// ignoring them. In the future, promise rejections that are not handled will
57
// terminate the Node.js process with a non-zero exit code.
68
process.on("unhandledRejection", err => {
79
throw err;
810
});
911

10-
process.env.NODE_ENV = "development";
11-
1212
// Ensure environment variables are read.
1313
require("../config/env");
1414

src/app/routes/TestRoute1.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 80px;
8+
}
9+
10+
.App-header {
11+
background-color: #222222;
12+
height: 150px;
13+
padding: 20px;
14+
color: #FFFFFF;
15+
}
16+
17+
.App-title {
18+
font-size: 1.5em;
19+
}
20+
21+
.App-intro {
22+
font-size: large;
23+
}
24+
25+
@keyframes App-logo-spin {
26+
from { transform: rotate(0deg); }
27+
to { transform: rotate(360deg); }
28+
}

src/app/routes/TestRoute1.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "./TestRoute1.scss";
2+
13
import * as React from "react";
24
import { FormattedMessage } from "react-intl";
35

0 commit comments

Comments
 (0)