Tôi biết babel-node
bỏ qua node_modules
theo mặc định, vì vậy tôi chạy nó ba cách khác nhau để ghi đè lên nó, tất cả thất bại:babel-nút thất bại trong việc yêu cầu tập tin jsx trong node_modules
chạy
babel-node app.js
với.babelrc
:{ "presets": ["es2015", "react"], "only": [ "app", "node_modules/react-components" ] }
kết quả:
SyntaxError: Unexpected token <
cho các mô-đun nút jsx cầnchạy 012.376.với
.babelrc
:{ "presets": ["es2015", "react"], "ignore": "node_modules\/(?!react-components)" }
kết quả:
SyntaxError: Unexpected token <
cho yêu cầu nút jsx mô-đunchạy
babel-node ./bin/www --ignore '/node_modules/(?!react-components)
với.babelrc
:{ "presets": ["es2015", "react"] }
kết quả:
[project]/node_modules/babel-preset-react/node_modules/babel-plugin-transform-react-jsx/lib/index.js:12 var visitor = require("babel-helper-builder-react-jsx")({ ^ TypeError: object is not a function
Sử dụng móc đăng ký với tùy chọn bỏ qua đã hoạt động chính xác.
chạy node app.js
với mã này vào đầu app.js
require('babel-core/register')({
ignore: /node_modules\/(?!react-components)/
});
Mặc dù công trình này, tôi vẫn muốn biết lý do tại sao việc triển khai của tôi với babel-node
không hoạt động. Cảm ơn.
tham khảo:
- How do I use babel in a node CLI program?
- import a module from node_modules with babel but failed
- http://babeljs.io/docs/usage/cli/
- http://babeljs.io/docs/usage/options/
Hãy hình dung điều này? – jcreamer898
@ jcreamer898 nope –