Skip to content

Commit 9eaa781

Browse files
poeschkophilipp-spiess
authored andcommitted
Add a checkbox to fixtures UI to choose React production build
1 parent e1a067d commit 9eaa781

File tree

5 files changed

+54
-12
lines changed

5 files changed

+54
-12
lines changed

fixtures/dom/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ coverage
99
# production
1010
build
1111
public/react.development.js
12+
public/react.production.min.js
1213
public/react-dom.development.js
14+
public/react-dom.production.min.js
1315
public/react-dom-server.browser.development.js
16+
public/react-dom-server.browser.production.min.js
1417

1518
# misc
1619
.DS_Store

fixtures/dom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"scripts": {
2020
"start": "react-scripts start",
21-
"prestart": "cp ../../build/dist/react.development.js ../../build/dist/react-dom.development.js ../../build/dist/react-dom-server.browser.development.js public/",
21+
"prestart": "cp ../../build/dist/react.development.js ../../build/dist/react-dom.development.js ../../build/dist/react.production.min.js ../../build/dist/react-dom.production.min.js ../../build/dist/react-dom-server.browser.development.js ../../build/dist/react-dom-server.browser.production.min.js public/",
2222
"build": "react-scripts build && cp build/index.html build/200.html",
2323
"test": "react-scripts test --env=jsdom",
2424
"eject": "react-scripts eject"

fixtures/dom/src/components/Header.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ class Header extends React.Component {
77
super(props, context);
88
const query = parse(window.location.search);
99
const version = query.version || 'local';
10+
const production = query.production || false;
1011
const versions = [version];
11-
this.state = {version, versions};
12+
this.state = {version, versions, production};
1213
}
1314
componentWillMount() {
1415
getVersionTags().then(tags => {
@@ -25,6 +26,14 @@ class Header extends React.Component {
2526
}
2627
window.location.search = stringify(query);
2728
}
29+
handleProductionChange(event) {
30+
const query = parse(window.location.search);
31+
query.production = event.target.checked;
32+
if (!query.production) {
33+
delete query.production;
34+
}
35+
window.location.search = stringify(query);
36+
}
2837
handleFixtureChange(event) {
2938
window.location.pathname = event.target.value;
3039
}
@@ -43,6 +52,15 @@ class Header extends React.Component {
4352
</span>
4453

4554
<div className="header-controls">
55+
<input
56+
id="react_production"
57+
type="checkbox"
58+
checked={this.state.production}
59+
onChange={this.handleProductionChange}
60+
/>
61+
<label htmlFor="react_production">
62+
<span className="header__label">Production</span>
63+
</label>
4664
<label htmlFor="example">
4765
<span className="sr-only">Select an example</span>
4866
<select

fixtures/dom/src/react-loader.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ function loadScript(src) {
3737
}
3838

3939
export function reactPaths() {
40-
let reactPath = 'react.development.js';
41-
let reactDOMPath = 'react-dom.development.js';
42-
let reactDOMServerPath = 'react-dom-server.browser.development.js';
43-
4440
let query = parseQuery(window.location.search);
4541
let version = query.version || 'local';
42+
let isProduction = query.production === 'true';
43+
44+
let environment = isProduction ? 'production.min' : 'development';
45+
46+
let reactPath = 'react.' + environment + '.js';
47+
let reactDOMPath = 'react-dom.' + environment + '.js';
48+
let reactDOMServerPath = 'react-dom-server.browser.' + environment + '.js';
4649

4750
if (version !== 'local') {
4851
const {major, minor, prerelease} = semver(version);
@@ -51,21 +54,34 @@ export function reactPaths() {
5154
// Load the old module location for anything less than 16 RC
5255
if (major >= 16 && !(minor === 0 && preReleaseStage === 'alpha')) {
5356
reactPath =
54-
'https://unpkg.com/react@' + version + '/umd/react.development.js';
57+
'https://unpkg.com/react@' +
58+
version +
59+
'/umd/react.' +
60+
environment +
61+
'.js';
5562
reactDOMPath =
5663
'https://unpkg.com/react-dom@' +
5764
version +
58-
'/umd/react-dom.development.js';
65+
'/umd/react-dom.' +
66+
environment +
67+
'.js';
5968
reactDOMServerPath =
6069
'https://unpkg.com/react-dom@' +
6170
version +
62-
'/umd/react-dom-server.browser.development';
71+
'/umd/react-dom-server.browser.' +
72+
environment +
73+
'.js';
6374
} else {
64-
reactPath = 'https://unpkg.com/react@' + version + '/dist/react.js';
75+
let suffix = isProduction ? '.min.js' : '.js';
76+
77+
reactPath = 'https://unpkg.com/react@' + version + '/dist/react' + suffix;
6578
reactDOMPath =
66-
'https://unpkg.com/react-dom@' + version + '/dist/react-dom.js';
79+
'https://unpkg.com/react-dom@' + version + '/dist/react-dom' + suffix;
6780
reactDOMServerPath =
68-
'https://unpkg.com/react-dom@' + version + '/dist/react-dom-server.js';
81+
'https://unpkg.com/react-dom@' +
82+
version +
83+
'/dist/react-dom-server' +
84+
suffix;
6985
}
7086
}
7187

fixtures/dom/src/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ textarea {
126126
width: 100%;
127127
}
128128

129+
.header__label {
130+
font-size: 12px;
131+
color: #ccc;
132+
}
133+
129134
.sr-only {
130135
clip: rect(0, 0, 0, 0);
131136
height: 0;

0 commit comments

Comments
 (0)