Skip to content

Commit b14588e

Browse files
committedJan 22, 2019
config updates
1 parent 5606be6 commit b14588e

File tree

4 files changed

+140
-17
lines changed

4 files changed

+140
-17
lines changed
 

‎package.json

+67-11
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,30 @@
3434
},
3535
"dependencies": {},
3636
"devDependencies": {
37+
"@babel/cli": "^7.2.3",
38+
"@babel/core": "7.1.6",
39+
"babel-core": "7.0.0-bridge.0",
40+
"babel-eslint": "9.0.0",
41+
"babel-jest": "23.6.0",
42+
"babel-loader": "8.0.4",
43+
"babel-plugin-named-asset-import": "^0.3.0",
3744
"babel-plugin-transform-object-rest-spread": "^6.26.0",
45+
"babel-preset-react-app": "^7.0.0",
3846
"cross-fetch": "^3.0.0",
47+
"eslint": "5.6.0",
48+
"eslint-config-react-app": "^3.0.6",
49+
"eslint-loader": "2.1.1",
50+
"eslint-plugin-flowtype": "2.50.1",
51+
"eslint-plugin-import": "2.14.0",
52+
"eslint-plugin-jsx-a11y": "6.1.2",
53+
"eslint-plugin-react": "7.11.1",
54+
"gzip-size": "^5.0.0",
55+
"jest": "23.6.0",
56+
"jest-pnp-resolver": "1.0.1",
57+
"jest-resolve": "23.6.0",
58+
"pretty-bytes": "^5.1.0",
3959
"react": "16.8.0-alpha.1",
4060
"react-dom": "16.8.0-alpha.1",
41-
"react-scripts": "2.1.3",
4261
"react-test-renderer": "16.8.0-alpha.1",
4362
"rollup": "^1.1.2",
4463
"rollup-plugin-babel": "^4.3.2",
@@ -48,18 +67,55 @@
4867
"rollup-plugin-uglify": "^6.0.1"
4968
},
5069
"scripts": {
51-
"start": "react-scripts start",
52-
"build": "react-scripts build",
53-
"test": "react-scripts test",
54-
"eject": "react-scripts eject"
70+
"build": "node scripts/build.js",
71+
"test": "node scripts/test.js"
5572
},
5673
"eslintConfig": {
5774
"extends": "react-app"
5875
},
59-
"browserslist": [
60-
">0.2%",
61-
"not dead",
62-
"not ie <= 11",
63-
"not op_mini all"
64-
]
76+
"jest": {
77+
"collectCoverageFrom": [
78+
"src/**/*.{js,jsx,ts,tsx}",
79+
"!src/**/*.d.ts"
80+
],
81+
"resolver": "jest-pnp-resolver",
82+
"testMatch": [
83+
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
84+
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
85+
],
86+
"testEnvironment": "jsdom",
87+
"testURL": "http://localhost",
88+
"transform": {
89+
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest"
90+
},
91+
"transformIgnorePatterns": [
92+
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
93+
"^.+\\.module\\.(css|sass|scss)$"
94+
],
95+
"moduleNameMapper": {
96+
"^react-native$": "react-native-web",
97+
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
98+
},
99+
"moduleFileExtensions": [
100+
"web.js",
101+
"js",
102+
"web.ts",
103+
"ts",
104+
"web.tsx",
105+
"tsx",
106+
"json",
107+
"web.jsx",
108+
"jsx",
109+
"node"
110+
]
111+
},
112+
"babel": {
113+
"presets": [[
114+
"react-app",
115+
{
116+
"helpers": false,
117+
"absoluteRuntime": false
118+
}
119+
]]
120+
}
65121
}

‎rollup.config.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import babel from "rollup-plugin-babel";
2-
import uglify from "rollup-plugin-uglify";
2+
import { uglify } from "rollup-plugin-uglify";
33
import replace from "rollup-plugin-replace";
44
import commonjs from "rollup-plugin-commonjs";
55
import resolve from "rollup-plugin-node-resolve";
66

7+
process.env.NODE_ENV = "production";
8+
79
const config = {
810
input: "src/index.js",
911
output: {
@@ -26,12 +28,9 @@ const config = {
2628
}),
2729
replace({
2830
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
29-
})
31+
}),
32+
uglify()
3033
]
3134
};
3235

33-
if (process.env.NODE_ENV === "production") {
34-
config.plugins.push(uglify());
35-
}
36-
3736
export default config;

‎scripts/build.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require("fs");
2+
const execSync = require("child_process").execSync;
3+
const prettyBytes = require("pretty-bytes");
4+
const gzipSize = require("gzip-size");
5+
6+
const exec = (command, extraEnv) =>
7+
execSync(command, {
8+
stdio: "inherit",
9+
env: Object.assign({}, process.env, extraEnv)
10+
});
11+
12+
console.log("\nBuilding UMD ...");
13+
exec("rollup --config rollup.config.js", {
14+
BABEL_ENV: "production",
15+
NODE_ENV: "production"
16+
});
17+
18+
const size = gzipSize.sync(fs.readFileSync("index.js"));
19+
console.log("\ngzipped, the UMD build is %s", prettyBytes(size));

‎scripts/test.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
// Do this as the first thing so that any code reading it knows the right env.
4+
process.env.BABEL_ENV = 'test';
5+
process.env.NODE_ENV = 'test';
6+
process.env.PUBLIC_URL = '';
7+
8+
// Makes the script crash on unhandled rejections instead of silently
9+
// ignoring them. In the future, promise rejections that are not handled will
10+
// terminate the Node.js process with a non-zero exit code.
11+
process.on('unhandledRejection', err => {
12+
throw err;
13+
});
14+
15+
const jest = require('jest');
16+
const execSync = require('child_process').execSync;
17+
let argv = process.argv.slice(2);
18+
19+
function isInGitRepository() {
20+
try {
21+
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
22+
return true;
23+
} catch (e) {
24+
return false;
25+
}
26+
}
27+
28+
function isInMercurialRepository() {
29+
try {
30+
execSync('hg --cwd . root', { stdio: 'ignore' });
31+
return true;
32+
} catch (e) {
33+
return false;
34+
}
35+
}
36+
37+
// Watch unless on CI, in coverage mode, or explicitly running all tests
38+
if (
39+
!process.env.CI &&
40+
argv.indexOf('--coverage') === -1 &&
41+
argv.indexOf('--watchAll') === -1
42+
) {
43+
// https://github.com/facebook/create-react-app/issues/5210
44+
const hasSourceControl = isInGitRepository() || isInMercurialRepository();
45+
argv.push(hasSourceControl ? '--watch' : '--watchAll');
46+
}
47+
48+
49+
jest.run(argv);

0 commit comments

Comments
 (0)