es6로 모듈을 작성하고 npm에 게시합니다. 다른 프로젝트에서 사용하고 싶으므로 다음과 같이 입력합니다.
import {ActionButton} from 'rcomponents'
하지만 작동하지 않았습니다.
D:\github\blog\node_modules\rcomponents\src\actionButton.jsx:1
(function (exports, require, module, __filename, __dirname) { import React fro
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) [as .jsx] (D:\github\blog\
node_modules\babel\node_modules\babel-core\lib\api\register\node.js:214:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at D:\github\blog\node_modules\rcomponents\src\index.js:3:19
at Object.<anonymous> (D:\github\blog\node_modules\rcomponents\src\index.js:
7:3)
다음은 webpack의 js 로더 구성입니다.
{ test: /\.jsx?$/, loader: `babel?cacheDirectory=${babelCache}` }
에서 아닌 모듈을 가져 오려고하면 node_modules
babel이 잘 작동합니다. 하지만에서 모듈을 가져 node_modules
오면 바벨이 작동하지 않는 것 같습니다.
바벨 문서 참조 :
참고 : 기본적으로 node_modules에 대한 모든 요구 사항은 무시됩니다. 무시 정규식을 전달하여이를 재정의 할 수 있습니다.
일반적으로의 모듈 node_modules
은 이미 사전에 트랜스 파일되었으므로 Babel에서 처리하지 않습니다. 그렇게하지 않을 경우 처리 할 수있는 파일을 알려야합니다. ignore
허용합니다.
require("babel/register")({
// Ignore everything in node_modules except node_modules/rcomponents.
ignore: /node_modules\/(?!rcomponents)/
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다