0
我,試圖建立一個資料庫我常用的反應組件然後我可以添加到我的項目,如component-kit
和重用這些,所以像大廈ES6類爲獨立的文件用的WebPack
import MyComponent from 'component-kit/MyComponent';
目前我有以下項目結構:
component-kit/
src/
MyComponent/
index.js
index.js
package.json
webpack.config.js
index.js
文件導入的所有組件按以下方式:
import('./MyComponent');
然後我用的WebPack構建每個這些進口到單獨的文件,這裏是我的配置是每間可用here
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
output: {
filename: 'dist.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'es2015', 'stage-0', 'react'],
plugins: ['syntax-dynamic-import']
}
}
}
]
}
};
在這個輸出2個文件dist.js
和0.dist.js
,我可以瞬間代碼分裂文檔不知道如何設置這個文件outputet有組件名稱,即MyComponent.js
,所以我可以比上面提到的包括它。 理想情況下,這些內容不會在其構建中包含反應,因爲它始終存在於父組件中。