Skip to content
This repository was archived by the owner on Jun 3, 2019. It is now read-only.

Commit 94a61ec

Browse files
diondirzactrlplusb
authored andcommitted
Another bug fixes, tweaks (#422)
* Fix lint * code split naming strategy sample * remove HTTP protocol to be more flexible * Refactor polyfill.io Due to counter route become broken in mobile device, use only default feature instead * Fix lint while prettier revert changes * update deps
1 parent 7ee3d42 commit 94a61ec

File tree

16 files changed

+106
-93
lines changed

16 files changed

+106
-93
lines changed

config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function resolveConfigForBrowserOrServer() {
3939
process.env.BUILD_FLAG_IS_NODE === 'true'
4040
) {
4141
// i.e. running in our server/node process.
42+
// eslint-disable-next-line global-require
4243
configCache = require('./values').default;
4344
return configCache;
4445
}

config/utils/envVars.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
* Please read the application configuration docs for more info.
77
*/
88

9-
import appRootDir from "app-root-dir";
10-
import colors from "colors/safe";
11-
import dotenv from "dotenv";
12-
import fs from "fs";
13-
import path from "path";
9+
import appRootDir from 'app-root-dir';
10+
import colors from 'colors/safe';
11+
import dotenv from 'dotenv';
12+
import fs from 'fs';
13+
import path from 'path';
1414

15-
import ifElse from "../../shared/utils/logic/ifElse";
16-
import removeNil from "../../shared/utils/arrays/removeNil";
15+
import ifElse from '../../shared/utils/logic/ifElse';
16+
import removeNil from '../../shared/utils/arrays/removeNil';
1717

1818
// PRIVATES
1919

2020
function registerEnvFile() {
2121
const DEPLOYMENT = process.env.DEPLOYMENT;
22-
const envFile = ".env";
22+
const envFile = '.env';
2323

2424
// This is the order in which we will try to resolve an environment configuration
2525
// file.
@@ -31,23 +31,16 @@ function registerEnvFile() {
3131
// Is there an environment config file at the app root for our target
3232
// environment name?
3333
// e.g. /projects/react-universally/.env.staging
34-
ifElse(DEPLOYMENT)(
35-
path.resolve(appRootDir.get(), `${envFile}.${DEPLOYMENT}`)
36-
)
34+
ifElse(DEPLOYMENT)(path.resolve(appRootDir.get(), `${envFile}.${DEPLOYMENT}`)),
3735
]);
3836

3937
// Find the first env file path match.
40-
const envFilePath = envFileResolutionOrder.find(filePath =>
41-
fs.existsSync(filePath));
38+
const envFilePath = envFileResolutionOrder.find(filePath => fs.existsSync(filePath));
4239

4340
// If we found an env file match the register it.
4441
if (envFilePath) {
45-
console.log(
46-
// eslint-disable-line no-console
47-
colors.bgBlue.white(
48-
`==> Registering environment variables from: ${envFilePath}`
49-
)
50-
);
42+
// eslint-disable-next-line no-console
43+
console.log(colors.bgBlue.white(`==> Registering environment variables from: ${envFilePath}`));
5144
dotenv.config({ path: envFilePath });
5245
}
5346
}
@@ -83,7 +76,5 @@ export function number(name, defaultVal) {
8376
}
8477

8578
export function bool(name, defaultVal) {
86-
return process.env[name]
87-
? process.env[name] === "true" || process.env[name] === "1"
88-
: defaultVal;
79+
return process.env[name] ? process.env[name] === 'true' || process.env[name] === '1' : defaultVal;
8980
}

config/values.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ const values = {
5858
// gets parsed.
5959
polyfillIO: {
6060
enabled: true,
61+
url: '//cdn.polyfill.io/v2/polyfill.min.js',
6162
// Reference https://qa.polyfill.io/v2/docs/features for a full list
6263
// of features.
6364
features: [
6465
// The default list.
6566
'default',
66-
// All es6 features.
67-
'es6',
67+
// If you want to add only es6 features.
68+
// 'es6',
6869
],
6970
},
7071

@@ -83,19 +84,19 @@ const values = {
8384
childSrc: [],
8485
connectSrc: [],
8586
defaultSrc: [],
86-
fontSrc: ['https://fonts.googleapis.com/css', 'https://fonts.gstatic.com'],
87+
fontSrc: ['fonts.googleapis.com/css', 'fonts.gstatic.com'],
8788
imgSrc: [],
8889
mediaSrc: [],
8990
manifestSrc: [],
9091
objectSrc: [],
9192
scriptSrc: [
92-
// Allow scripts from https://cdn.polyfill.io so that we can import the
93+
// Allow scripts from cdn.polyfill.io so that we can import the
9394
// polyfill.
94-
'https://cdn.polyfill.io',
95+
'cdn.polyfill.io',
9596
],
9697
styleSrc: [
97-
'https://cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css',
98-
'https://fonts.googleapis.com/css',
98+
'cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css',
99+
'fonts.googleapis.com/css',
99100
],
100101
},
101102

internal/development/hotDevelopment.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class HotDevelopment {
6969

7070
const nodeBundles = [initializeBundle('server', config('bundles.server'))].concat(
7171
Object.keys(config('additionalNodeBundles')).map(name =>
72-
initializeBundle(name, config('additionalNodeBundles')[name])),
72+
initializeBundle(name, config('additionalNodeBundles')[name]),
73+
),
7374
);
7475

7576
Promise.resolve(
@@ -104,7 +105,7 @@ class HotDevelopment {
104105
}
105106

106107
dispose() {
107-
const safeDisposer = server => server ? server.dispose() : Promise.resolve();
108+
const safeDisposer = server => (server ? server.dispose() : Promise.resolve());
108109

109110
// First the hot client server.
110111
return (

internal/webpack/withServiceWorker/index.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,32 @@ export default function withServiceWorker(webpackConfig, bundleConfig) {
106106
// if you needed.
107107
AppCache: false,
108108
// Which external files should be included with the service worker?
109-
externals:
110-
// Add the polyfill io script as an external if it is enabled.
111-
(
112-
config('polyfillIO.enabled')
113-
? [`https://cdn.polyfill.io/v2/polyfill.min.js?features=${config('polyfillIO.features').join(',')}`]
114-
: []
115-
)
109+
// Add the polyfill io script as an external if it is enabled.
110+
externals: (config('polyfillIO.enabled')
111+
? [`${config('polyfillIO.url')}?features=${config('polyfillIO.features').join(',')}`]
112+
: [])
116113
// Add any included public folder assets.
117114
.concat(
118115
config('serviceWorker.includePublicAssets').reduce((acc, cur) => {
119116
const publicAssetPathGlob = path.resolve(
120-
appRootDir.get(), config('publicAssetsPath'), cur,
117+
appRootDir.get(),
118+
config('publicAssetsPath'),
119+
cur,
121120
);
122121
const publicFileWebPaths = acc.concat(
123122
// First get all the matching public folder files.
124123
globSync(publicAssetPathGlob, { nodir: true })
125-
// Then map them to relative paths against the public folder.
126-
// We need to do this as we need the "web" paths for each one.
127-
.map(publicFile => path.relative(
128-
path.resolve(appRootDir.get(), config('publicAssetsPath')),
129-
publicFile,
130-
))
131-
// Add the leading "/" indicating the file is being hosted
132-
// off the root of the application.
133-
.map(relativePath => `/${relativePath}`),
124+
// Then map them to relative paths against the public folder.
125+
// We need to do this as we need the "web" paths for each one.
126+
.map(publicFile =>
127+
path.relative(
128+
path.resolve(appRootDir.get(), config('publicAssetsPath')),
129+
publicFile,
130+
),
131+
)
132+
// Add the leading "/" indicating the file is being hosted
133+
// off the root of the application.
134+
.map(relativePath => `/${relativePath}`),
134135
);
135136
return publicFileWebPaths;
136137
}, []),

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@
114114
"md5": "2.2.1",
115115
"modernizr-loader": "1.0.1",
116116
"node-notifier": "5.1.2",
117-
"prettier": "1.1.0",
117+
"prettier": "1.2.2",
118118
"prettier-eslint": "5.1.0",
119-
"prettier-eslint-cli": "3.3.0",
119+
"prettier-eslint-cli": "3.4.1",
120120
"react-addons-test-utils": "15.5.1",
121121
"react-hot-loader": "3.0.0-beta.6",
122122
"react-test-renderer": "15.5.4",

server/middleware/reactApplication/ServerHTML.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ function scriptTag(jsFilePath) {
4040
// COMPONENT
4141

4242
function ServerHTML(props) {
43-
const {
44-
asyncComponentsState,
45-
helmet,
46-
nonce,
47-
reactAppString,
48-
} = props;
43+
const { asyncComponentsState, helmet, nonce, reactAppString } = props;
4944

5045
// Creates an inline script definition that is protected by the nonce.
5146
const inlineScript = body => (
@@ -72,14 +67,14 @@ function ServerHTML(props) {
7267
ifElse(asyncComponentsState)(() =>
7368
inlineScript(
7469
`window.__ASYNC_COMPONENTS_REHYDRATE_STATE__=${serialize(asyncComponentsState)};`,
75-
)),
70+
),
71+
),
7672
// Enable the polyfill io script?
7773
// This can't be configured within a react-helmet component as we
7874
// may need the polyfill's before our client JS gets parsed.
7975
ifElse(config('polyfillIO.enabled'))(() =>
80-
scriptTag(
81-
`https://cdn.polyfill.io/v2/polyfill.min.js?features=${config('polyfillIO.features').join(',')}`,
82-
)),
76+
scriptTag(`${config('polyfillIO.url')}?features=${config('polyfillIO.features').join(',')}`),
77+
),
8378
// When we are in development mode our development server will
8479
// generate a vendor DLL in order to dramatically reduce our
8580
// compilation times. Therefore we need to inject the path to the
@@ -89,7 +84,8 @@ function ServerHTML(props) {
8984
)(() =>
9085
scriptTag(
9186
`${config('bundles.client.webPath')}${config('bundles.client.devVendorDLL.name')}.js?t=${Date.now()}`,
92-
)),
87+
),
88+
),
9389
ifElse(clientEntryAssets && clientEntryAssets.js)(() => scriptTag(clientEntryAssets.js)),
9490
...ifElse(helmet)(() => helmet.script.toComponent(), []),
9591
]);

server/middleware/reactApplication/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function reactApplicationMiddleware(request, response) {
3131
// SSR is disabled so we will return an "empty" html page and
3232
// rely on the client to initialize and render the react application.
3333
const html = renderToStaticMarkup(<ServerHTML nonce={nonce} />);
34-
response.status(200).send(html);
34+
response.status(200).send(`<!DOCTYPE html>${html}`);
3535
return;
3636
}
3737

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { asyncComponent } from 'react-async-component';
22

33
export default asyncComponent({
4-
resolve: () => System.import('./AboutRoute'),
4+
// include home and about route in same chunk e.g main
5+
resolve: () => System.import(/* webpackChunkName: "main" */ './AboutRoute'),
56
});

shared/components/DemoApp/AsyncCounterRoute/CounterRoute.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/no-unescaped-entities */
12
import React, { Component } from 'react';
23

34
class CounterRoute extends Component {

0 commit comments

Comments
 (0)