Target latest Node for backend applications (#213)
Summary: Consequently, Babel won’t transform classes to their roughly equivalent ES5 counterparts, etc. Test Plan: Create `src/classy.js` with `class X {}; console.log(X);`. Then, add a build target for `classy: resolveApp("src/classy.js"),` in `paths.js`. Use `yarn backend` and inspect the contents of `bin/classy.js`; in particular, look at the definition of `X` (whatever the argument to `console.log` is). Before this commit, the result will be a big complicated mess. After this commit, it will be `class X {}`. Note also that `yarn travis --full` passes, indicating that the two manual tests, which call out to the utilities in `bin/`, still work. wchargin-branch: target-node
This commit is contained in:
parent
b5e894bbb4
commit
e9dbdeca96
|
@ -49,6 +49,7 @@ const plugins = [
|
|||
// https://github.com/facebookincubator/create-react-app/issues/720
|
||||
// It’s also nice that we can enforce `NODE_ENV` being specified.
|
||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||
var backend = !!process.env.SOURCECRED_BACKEND;
|
||||
if (env !== "development" && env !== "test" && env !== "production") {
|
||||
throw new Error(
|
||||
"Using `babel-preset-react-app` requires that you specify `NODE_ENV` or " +
|
||||
|
@ -101,11 +102,12 @@ if (env === "test") {
|
|||
[
|
||||
require.resolve("babel-preset-env"),
|
||||
{
|
||||
targets: {
|
||||
// React parses on ie 9, so we should too
|
||||
targets: backend
|
||||
? {
|
||||
node: "current",
|
||||
}
|
||||
: {
|
||||
ie: 9,
|
||||
// We currently minify with uglify
|
||||
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
|
||||
uglify: true,
|
||||
},
|
||||
// Disable polyfill transforms
|
||||
|
@ -117,7 +119,14 @@ if (env === "test") {
|
|||
// JSX, Flow
|
||||
require.resolve("babel-preset-react"),
|
||||
],
|
||||
plugins: plugins.concat([
|
||||
plugins: plugins.concat(
|
||||
backend
|
||||
? [
|
||||
// Must come before `babel-plugin-transform-regenerator`.
|
||||
require.resolve("babel-plugin-transform-es2015-for-of"),
|
||||
]
|
||||
: [],
|
||||
[
|
||||
// function* () { yield 42; yield 43; }
|
||||
[
|
||||
require.resolve("babel-plugin-transform-regenerator"),
|
||||
|
@ -128,7 +137,8 @@ if (env === "test") {
|
|||
],
|
||||
// Adds syntax support for import()
|
||||
require.resolve("babel-plugin-syntax-dynamic-import"),
|
||||
]),
|
||||
]
|
||||
),
|
||||
};
|
||||
|
||||
if (env === "production") {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"babel-eslint": "7.2.3",
|
||||
"babel-jest": "20.0.3",
|
||||
"babel-loader": "7.1.2",
|
||||
"babel-plugin-transform-es2015-for-of": "^6.23.0",
|
||||
"babel-preset-react-app": "^3.1.1",
|
||||
"babel-runtime": "6.26.0",
|
||||
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || "development";
|
||||
process.env.BABEL_ENV = process.env.NODE_ENV;
|
||||
process.env.SOURCECRED_BACKEND = true;
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
|
|
Loading…
Reference in New Issue