0
目前,直到庫被分割成JS框架特定的Repos(React,JQuery,Angular等),我在一個npm模塊中有多個庫(是,這是正確的反模式)。一個節點模塊,兩個庫,一個導出在ES6中
但幽默我,如何導出其中一個庫而不導出其他庫?我不想要jquery模塊,如果我只使用React,並且package.json
中只有一個「主」。
一個選項是通過相對目錄from './node_modules/ui-combined-module/src/react/dist.js';
導入模塊,但是看起來相當混亂。
對於
// Use one of the following in your example code:
// import {react as UILibraryReact} from 'ui-combined-module';
// const Badge = UILibraryReact.Badge;
// import {jquery as UILibraryJquery} from 'ui-combined-module';
// const Badge = UILibraryJquery.Badge;
import * as react from './react/dist';
import * as jquery from './jquery/dist';
module.exports = {
react,
jquery
};
我覺得你上面的'export'聲明,你仍然需要導入這兩個反應和jQuery模塊,否則你無法回報他們,因爲他們不會定義。 –
我想你可以用舊的require語法替換'react' if(lib ==='react')return require('react')' – denixtry