Skip to content

Commit eb8270c

Browse files
authored
Reuse babel options and specify polyfills for karma explicitely (#1456)
* reuse babel options * add envioronment requirements * manually serialize a collection, because with ['@babel/env', {loose: true}] the spread is doing a different thing * avoid requiring polyfill for IE11 * make it clear that adding new polyfills to JSS implicite dependencies is a breaking change * use specific polyfills * build * add function name polyfill for IE9 * add raf polyfill * revert changes to yarn.lock * add core-js and remove babel-polyfill from yarn * update snapshots after merge * prettier * for in doesn't work on on collections in safari 7,8 * update environments description * link environment-requirements * remove plugin-proposal-export-namespace-from
1 parent 06f10e7 commit eb8270c

17 files changed

Lines changed: 93 additions & 92 deletions

File tree

babelOptions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.getBabelOptions = ({useESModules}) => ({
2+
presets: [['@babel/env', {loose: true}], '@babel/flow', '@babel/react'],
3+
plugins: [
4+
['@babel/proposal-class-properties', {loose: true}],
5+
['@babel/transform-runtime', {useESModules}],
6+
['dev-expression']
7+
]
8+
})

docs/environment-requirements.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## JavaScript Environment Requirements
2+
3+
We run our tests against a [number of real browsers](../browsers.json) including IE9, but we do NOT include polyfills we rely on in the build. It is up to the user to include polyfills depending on what environment they need to support. Here is a [full list of polyfills](../polyfills.js) you will need if you support ALL browsers JSS does.
4+
5+
We consider adding a requirement to a new polyfill - a breaking change and it will require a major version incrementation.
6+
7+
We recommend using [babel-preset-env](https://babeljs.io/docs/en/babel-preset-env), which is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

docs/setup.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Alternatively, you can use [unpkg CDN](./cdn.md).
1010

1111
## Polyfills
1212

13-
If you support browsers which do not have support for the following features, make sure you provide polyfills for them.
14-
15-
- WeakMap
13+
Check out the [environment requirements](./environment-requirements.md) as well as our browsers support and required polyfills.
1614

1715
## Setup with the default preset
1816

karma.conf.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ module.exports = config => {
1616
browsers: ['Chrome'],
1717
frameworks: ['mocha'],
1818
files: [
19-
'node_modules/@babel/polyfill/dist/polyfill.js',
20-
'node_modules/raf/polyfill.js',
21-
19+
'./polyfills.js',
2220
'./packages/*/tests/*.js',
2321
'./packages/*/tests/**/*.js',
2422
'./packages/*/src/**/*.test.js'
2523
],
2624
preprocessors: {
27-
'node_modules/raf/polyfill.js': ['webpack'],
25+
'./polyfills.js': ['webpack', 'sourcemap'],
2826
'./packages/**/*.js': ['webpack', 'sourcemap']
2927
},
3028
webpack,

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
"devDependencies": {
4646
"@babel/core": "^7.2.2",
4747
"@babel/plugin-proposal-class-properties": "^7.3.0",
48-
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
4948
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
5049
"@babel/plugin-transform-runtime": "^7.2.0",
51-
"@babel/polyfill": "^7.2.5",
5250
"@babel/preset-env": "^7.3.1",
5351
"@babel/preset-flow": "^7.0.0",
5452
"@babel/preset-react": "^7.0.0",
@@ -65,6 +63,7 @@
6563
"chalk": "^2.4.1",
6664
"codecov": "^3.6.5",
6765
"common-tags": "^1.4.0",
66+
"core-js": "^3.9.1",
6867
"cross-env": "^3.1.3",
6968
"css.escape": "^1.5.1",
7069
"detect-browser": "^1.5.0",

packages/css-jss/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"css-jss.js": {
3-
"bundled": 61133,
4-
"minified": 21942,
5-
"gzipped": 7382
3+
"bundled": 61186,
4+
"minified": 21939,
5+
"gzipped": 7380
66
},
77
"css-jss.min.js": {
8-
"bundled": 60058,
9-
"minified": 21319,
10-
"gzipped": 7102
8+
"bundled": 60111,
9+
"minified": 21316,
10+
"gzipped": 7100
1111
},
1212
"css-jss.cjs.js": {
1313
"bundled": 3034,

packages/jss-plugin-default-unit/.size-snapshot.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"jss-plugin-default-unit.js": {
3-
"bundled": 6918,
4-
"minified": 3637,
5-
"gzipped": 1245
3+
"bundled": 6971,
4+
"minified": 3634,
5+
"gzipped": 1244
66
},
77
"jss-plugin-default-unit.min.js": {
8-
"bundled": 6918,
9-
"minified": 3637,
10-
"gzipped": 1245
8+
"bundled": 6971,
9+
"minified": 3634,
10+
"gzipped": 1244
1111
},
1212
"jss-plugin-default-unit.cjs.js": {
13-
"bundled": 6097,
14-
"minified": 3721,
13+
"bundled": 6150,
14+
"minified": 3718,
1515
"gzipped": 1194
1616
},
1717
"jss-plugin-default-unit.esm.js": {
18-
"bundled": 6017,
19-
"minified": 3655,
18+
"bundled": 6070,
19+
"minified": 3652,
2020
"gzipped": 1137,
2121
"treeshaked": {
2222
"rollup": {

packages/jss-plugin-default-unit/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function iterate(prop: string, value: any, options: Options) {
4040
value[innerProp] = iterate(`${prop}-${innerProp}`, value[innerProp], options)
4141
}
4242
}
43-
} else if (typeof value === 'number' && !Number.isNaN(value)) {
43+
// eslint-disable-next-line no-restricted-globals
44+
} else if (typeof value === 'number' && isNaN(value) === false) {
4445
const unit = options[prop] || units[prop]
4546

4647
// Add the unit if available, except for the special case of 0px.

packages/jss-preset-default/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"jss-preset-default.js": {
3-
"bundled": 58333,
4-
"minified": 21166,
5-
"gzipped": 7034
3+
"bundled": 58386,
4+
"minified": 21163,
5+
"gzipped": 7032
66
},
77
"jss-preset-default.min.js": {
8-
"bundled": 57258,
9-
"minified": 20543,
10-
"gzipped": 6755
8+
"bundled": 57311,
9+
"minified": 20540,
10+
"gzipped": 6753
1111
},
1212
"jss-preset-default.cjs.js": {
1313
"bundled": 2222,

packages/jss-starter-kit/.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"jss-starter-kit.js": {
3-
"bundled": 74476,
4-
"minified": 31617,
5-
"gzipped": 9666
3+
"bundled": 74529,
4+
"minified": 31614,
5+
"gzipped": 9664
66
},
77
"jss-starter-kit.min.js": {
8-
"bundled": 73401,
9-
"minified": 31429,
10-
"gzipped": 9442
8+
"bundled": 73454,
9+
"minified": 31426,
10+
"gzipped": 9441
1111
},
1212
"jss-starter-kit.cjs.js": {
1313
"bundled": 5647,

0 commit comments

Comments
 (0)