Skip to content

Commit 53537aa

Browse files
JayCanuckaarontam
authored andcommitted
PLAT-40726 & ENYO-4798: Support babel-preset-env with dynamic targetted babel-polyfill usage (#102)
* Removed babel-plugin-syntax-dynamic-import as it's already included via stage-0 preset. Removed babel-plugin-transform-react-constant-elements due to known issues (see facebook/create-react-app#553) * PLAT-40726: Support babel-preset-env with dynamic targetted babel-polyfill usage. * ENYO-4798: Babel improvements via additional plugins * Remove blank comment line * Exclude transform-regenerator to avoid regenerator runtime as that's not a supported feature anyway. * Disable web.dom.iterable polyfill as its window/DOM-related and not a strict js polyfill. Unneeded for context of Enact app. * Remove webOS build option. Instead, for webOS,set target browser or BROWSERSLIST env var to "Chrome 53" * Remove webOS alias option Reviewed-By: Roy Sutton ([email protected]) Integrated-By: Aaron Tam ([email protected])
1 parent 843fe48 commit 53537aa

File tree

6 files changed

+62
-47
lines changed

6 files changed

+62
-47
lines changed

config/.babelrc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
{
2-
"presets": [["es2015", {"modules": false}], "stage-0", "react"],
3-
"plugins": ["dev-expression", "syntax-dynamic-import"],
4-
"env": {
5-
"production": {
6-
"plugins": ["transform-react-inline-elements","transform-react-constant-elements"]
7-
}
8-
}
2+
"presets": ["./.babelrc.js"]
93
}

config/.babelrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* .babelrc.js
3+
*
4+
* A forward-compatible Babel javascript configuration dynamically setup
5+
* for Enact development environment on target platforms.
6+
*/
7+
8+
const app = require('@enact/dev-utils/option-parser');
9+
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
10+
11+
module.exports = {
12+
presets: [
13+
['env', {
14+
targets: Object.assign({uglify:true},
15+
app.browsers && {browsers:app.browsers},
16+
app.node && {node: app.node}),
17+
exclude: ['transform-regenerator', 'web.dom.iterable', 'web.timers', 'web.immediate'],
18+
useBuiltIns: true,
19+
modules: false
20+
}],
21+
'stage-0',
22+
'react'
23+
],
24+
plugins: [
25+
'dev-expression',
26+
env !== 'production' && 'transform-react-jsx-self',
27+
env !== 'production' && 'transform-react-jsx-source',
28+
env === 'production' && 'transform-react-inline-elements'
29+
].filter(Boolean)
30+
};

config/karma.conf.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ module.exports = function(karma) {
9696
babelrc: false,
9797
extends: path.join(__dirname, '.babelrc'),
9898
// @remove-on-eject-end
99-
cacheDirectory: true
99+
cacheDirectory: true,
100+
// Generate a unique identifier string based off versons of components and app config.
101+
cacheIdentifier: JSON.stringify({
102+
'babel-loader': require('babel-loader/package.json').version,
103+
'babel-core': require('babel-core/package.json').version,
104+
browsers: app.browsers,
105+
node: app.node
106+
})
100107
}
101108
},
102109
{

config/polyfills.js

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
/* global global */
2-
// @remove-on-eject-begin
3-
/**
4-
* Copyright (c) 2015-present, Facebook, Inc.
5-
* All rights reserved.
1+
/* eslint no-var: off */
2+
/*
3+
* polyfills.js
64
*
7-
* This source code is licensed under the BSD-style license found in the
8-
* LICENSE file in the root directory of this source tree. An additional grant
9-
* of patent rights can be found in the PATENTS file in the same directory.
5+
* A collections of polyfills required prior to loading the app.
106
*/
11-
// @remove-on-eject-end
127

13-
if (typeof global !== 'undefined') {
14-
if (typeof Promise === 'undefined') {
15-
// Rejection tracking prevents a common issue where React gets into an
16-
// inconsistent state due to an error, but it gets swallowed by a Promise,
17-
// and the user has no idea what causes React's erratic future behavior.
18-
require('promise/lib/rejection-tracking').enable();
19-
global.Promise = require('promise/lib/es6-extensions');
20-
}
8+
// Temporarily remap [Array].toLocaleString to [Array].toString.
9+
// Fixes an issue with loading the polyfills within the v8 snapshot environment
10+
// where toLocaleString() within the TypedArray polyfills causes snapshot failure.
11+
var origToLocaleString = Array.prototype.toLocaleString;
12+
Array.prototype.toLocaleString = Array.prototype.toString;
2113

22-
// fetch() polyfill for making API calls.
23-
require('whatwg-fetch');
24-
}
14+
require('babel-polyfill');
2515

26-
if (!Math.sign) {
27-
Math.sign = function(x) {
28-
// If -0, must return -0.
29-
return isNaN(x) ? NaN : x < 0 ? -1 : x > 0 ? 1 : +x;
30-
}
31-
}
32-
33-
// Common String ES6 functionalities for character values.
34-
// Used by Enact's Moonstone library.
35-
require('string.fromcodepoint');
36-
require('string.prototype.codepointat');
37-
38-
// Object.assign() is commonly used with Enact and React.
39-
// It will use the native implementation if it's present and isn't buggy.
40-
Object.assign = require('object-assign');
16+
// Restore real [Array].toLocaleString for runtime usage.
17+
Array.prototype.toLocaleString = origToLocaleString;

config/webpack.config.dev.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,14 @@ module.exports = {
132132
// This is a feature of `babel-loader` for webpack (not Babel itself).
133133
// It enables caching results in ./node_modules/.cache/babel-loader/
134134
// directory for faster rebuilds.
135-
cacheDirectory: true
135+
cacheDirectory: true,
136+
// Generate a unique identifier string based off versons of components and app config.
137+
cacheIdentifier: JSON.stringify({
138+
'babel-loader': require('babel-loader/package.json').version,
139+
'babel-core': require('babel-core/package.json').version,
140+
browsers: app.browsers,
141+
node: app.node
142+
})
136143
}
137144
},
138145
// Multiple styling-support features are used together.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"babel-eslint": "~8.0.1",
2323
"babel-loader": "~7.1.2",
2424
"babel-plugin-dev-expression": "~0.2.1",
25-
"babel-plugin-syntax-dynamic-import": "~6.18.0",
2625
"babel-plugin-transform-es2015-modules-commonjs": "~6.26.0",
27-
"babel-plugin-transform-react-constant-elements": "~6.23.0",
2826
"babel-plugin-transform-react-inline-elements": "~6.22.0",
29-
"babel-preset-es2015": "~6.24.1",
27+
"babel-plugin-transform-react-jsx-self": "~6.22.0",
28+
"babel-plugin-transform-react-jsx-source": "~6.22.0",
29+
"babel-preset-env": "~1.6.0",
3030
"babel-preset-react": "~6.24.1",
3131
"babel-preset-stage-0": "~6.24.1",
3232
"case-sensitive-paths-webpack-plugin": "~2.1.1",

0 commit comments

Comments
 (0)