저는 Babel을 프로그래밍 방식으로 사용합니다. 플러그인이 거의 필요하지 않고 모든 것이 잘 작동합니다.프로그래밍 방식으로 바벨 변환/플러그인에 옵션을 전달하는 방법은 무엇입니까?
Tho, 바벨 변환에 옵션을 전달하고 싶습니다. 나는 내가 아직 그 일을하지 않았 음을 깨달았고, 나는 단지 노력하지 않는 것이 효과가없는 것처럼 보였다.
특히 글로벌 엄격 모드를 사용하지 않으려면 babel-transform-strict-mode
을 포함하고 strict:false
을 전달하고 싶습니다. 내가 가진 내 코드에서
// with options
{
"plugins": [
["transform-strict-mode", {
"strict": true
}]
]
}
:
워드 프로세서는 .babelrc
파일을 가지고 때를 사용하는 방법에 대해 설명
const babelify = require("babelify")
, es2015 = require("babel-preset-es2015")
, reactify = require("babel-preset-react")
, strictMode = require("babel-plugin-transform-strict-mode")
;
...
this.browserify.transform(babelify, {
global: true,
babelrc: false,
presets: [
reactify
, es2015
, [
strictMode
, { strict: false }
]
]
});
es2015
하면서 presets
배열에 큰 reactify
일, strictMode
추가 { strict: false }
은 작동하지 않습니다.
오류 :
ReferenceError: [BABEL] /home/.../index.js: Unknown option: foreign.visitor.
Check out http://babeljs.io/docs/usage/options/ for more
information about options.
A common cause of this error is the presence of a
configuration options object without the corresponding
preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
For more detailed information on preset configuration,
please see
http://babeljs.io/docs/plugins/#pluginpresets-options.
나는이 다른 모듈의 일부이기 때문에, 그것은 분명, 모듈을 찾을 수 없습니다 이름 (["transform-strict-mode", { strict: false }]
를) 변환 strictMode
대신 사용하는 경우.
require
모듈 (이 경우 strictMode
)에 프로그래밍 방식으로 (babelrc
없이) 옵션을 전달할 수 있습니까?
아, 재미 있습니다. 그러면 foo를 "foo"에서 더 이상 가져올 수 없다는 뜻입니까? 나는 [this plugin] (https://github.com/genify/babel-plugin-transform-remove-strict-mode)을 사용하여 끝났는데, 아마도 그것은 단지 "엄격한 사용"을 제거 할 뿐이다. 감사! –
그럴만 한 옵션입니다. 코드가 더 이상 규격을 따르지 않기 때문에 Node에 도착한 후에 ES6 모듈을 사용하려면 CommonJS를 사용하지 않고도이 문제를 다시 해결할 수 없습니다. – loganfsmyth
클라이언트 측에서'if (this._) {...} '를 검사했지만'this'가'undefined' 였기 때문에 일부 라이브러리 (예 :'밑줄')를 사용하는 데 문제가있었습니다. 따라서 실패했습니다 . –