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
|
// https://github.com/facebookincubator/create-react-app/issues/720
|
||||||
// It’s also nice that we can enforce `NODE_ENV` being specified.
|
// It’s also nice that we can enforce `NODE_ENV` being specified.
|
||||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||||
|
var backend = !!process.env.SOURCECRED_BACKEND;
|
||||||
if (env !== "development" && env !== "test" && env !== "production") {
|
if (env !== "development" && env !== "test" && env !== "production") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Using `babel-preset-react-app` requires that you specify `NODE_ENV` or " +
|
"Using `babel-preset-react-app` requires that you specify `NODE_ENV` or " +
|
||||||
|
@ -101,13 +102,14 @@ if (env === "test") {
|
||||||
[
|
[
|
||||||
require.resolve("babel-preset-env"),
|
require.resolve("babel-preset-env"),
|
||||||
{
|
{
|
||||||
targets: {
|
targets: backend
|
||||||
// React parses on ie 9, so we should too
|
? {
|
||||||
ie: 9,
|
node: "current",
|
||||||
// We currently minify with uglify
|
}
|
||||||
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
|
: {
|
||||||
uglify: true,
|
ie: 9,
|
||||||
},
|
uglify: true,
|
||||||
|
},
|
||||||
// Disable polyfill transforms
|
// Disable polyfill transforms
|
||||||
useBuiltIns: false,
|
useBuiltIns: false,
|
||||||
// Do not transform modules to CJS
|
// Do not transform modules to CJS
|
||||||
|
@ -117,18 +119,26 @@ if (env === "test") {
|
||||||
// JSX, Flow
|
// JSX, Flow
|
||||||
require.resolve("babel-preset-react"),
|
require.resolve("babel-preset-react"),
|
||||||
],
|
],
|
||||||
plugins: plugins.concat([
|
plugins: plugins.concat(
|
||||||
// function* () { yield 42; yield 43; }
|
backend
|
||||||
|
? [
|
||||||
|
// Must come before `babel-plugin-transform-regenerator`.
|
||||||
|
require.resolve("babel-plugin-transform-es2015-for-of"),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
[
|
[
|
||||||
require.resolve("babel-plugin-transform-regenerator"),
|
// function* () { yield 42; yield 43; }
|
||||||
{
|
[
|
||||||
// Async functions are converted to generators by babel-preset-env
|
require.resolve("babel-plugin-transform-regenerator"),
|
||||||
async: false,
|
{
|
||||||
},
|
// Async functions are converted to generators by babel-preset-env
|
||||||
],
|
async: false,
|
||||||
// Adds syntax support for import()
|
},
|
||||||
require.resolve("babel-plugin-syntax-dynamic-import"),
|
],
|
||||||
]),
|
// Adds syntax support for import()
|
||||||
|
require.resolve("babel-plugin-syntax-dynamic-import"),
|
||||||
|
]
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (env === "production") {
|
if (env === "production") {
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"babel-eslint": "7.2.3",
|
"babel-eslint": "7.2.3",
|
||||||
"babel-jest": "20.0.3",
|
"babel-jest": "20.0.3",
|
||||||
"babel-loader": "7.1.2",
|
"babel-loader": "7.1.2",
|
||||||
|
"babel-plugin-transform-es2015-for-of": "^6.23.0",
|
||||||
"babel-preset-react-app": "^3.1.1",
|
"babel-preset-react-app": "^3.1.1",
|
||||||
"babel-runtime": "6.26.0",
|
"babel-runtime": "6.26.0",
|
||||||
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
"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.
|
// 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.NODE_ENV = process.env.NODE_ENV || "development";
|
||||||
process.env.BABEL_ENV = process.env.NODE_ENV;
|
process.env.BABEL_ENV = process.env.NODE_ENV;
|
||||||
|
process.env.SOURCECRED_BACKEND = true;
|
||||||
|
|
||||||
// Makes the script crash on unhandled rejections instead of silently
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
// ignoring them. In the future, promise rejections that are not handled will
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
|
Loading…
Reference in New Issue