Webpack에서 UMD 번들을 생성하도록 구성하여 AMD 및 CommonJS의 패키지 이름을 소문자 (척추)로 지정하고 전역 컨텍스트에 CamelCase 이름?CamelCase 및 Spinal-case 이름이 포함 된 Webpack 출력 UMD 라이브러리
(function(f) {
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f(require('react'));
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(['react'], f);
// <script>
} else {
var g;
if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
// works providing we're not in "use strict";
// needed for Java 8 Nashorn
// see https://github.com/facebook/react/issues/3037
g = this;
}
g.ReactDOM = f(g.React);
}
})(function(React)...
예를 들어, ES6을 사용하면 'react-dom;'에서 'ReactDOM 가져 오기', 'var ReactDOM = require ('react ');' RequireJS를 사용하고 단순히 파일에 스크립트를 추가 할 때'ReactDOM' ('window.ReactDOM')을 호출하면됩니다. ReactJS 번들보기 https://npmcdn.com/[email protected]/dist/react-dom.js –
@AlexanderShutov, 더 나은 예를 들어 답을 업데이트했고, 더 나은 예제와 함께 탐색하고 실험 할 수있는 레포 . – KevBot
마침내 내가 필요로하는 것은'umdDefineName'을 제거해야했기 때문에 AMD와 CommonJS 섹션은 이름없이 사용됩니다. CommonJS는 어떤 이유로 Webpack에 의해 남겨 지지만 Webpack 또는 Rollup에서 가져올 때 운 좋게 무시됩니다. 마지막으로 [React 팀이하는 방법] (https://github.com/facebook/react/blob/046f7448d7224da5b33441248a32a319a6464bc5/grunt/config/browserify.js#L98)을보십시오. –