我正在创建我的第一个reactjs
库,它使用了material-ui和react-google-charts以及其他一些第三方库。我使用的WebPack(3.5.6版本)作为我的捆绑,到目前为止,我有以下webpack.config.js
文件...如何管理/打包可重复使用的反应库中的依赖项
const webpack = require('webpack')
const path = require('path')
const BUILD_DIR = path.resolve(__dirname, 'lib')
const APP_DIR = path.resolve(__dirname, 'src')
const WebpackConfig = {
entry: {
app: APP_DIR + '/index.js',
},
output: {
path: BUILD_DIR,
filename: 'index.js',
libraryTarget: 'umd',
library: 'TestComponent'
},
module: {
loaders: [
{
loader: 'babel-loader',
test: /.js$/,
exclude: /node_modules/,
include : APP_DIR,
options: {
presets: [ 'react', 'es2015', 'stage-2' ]
}
}
],
},
}
// webpack production config.
if (process.env.NODE_ENV === 'production') {
WebpackConfig.externals = {
'react': 'react',
'react-dom': 'react-dom'
}
WebpackConfig.plugins = [
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
},
compress: {
warnings: false,
screw_ie8: true
},
comments: false
}),
]
}
module.exports = WebpackConfig
在生产中,我已经打上react
和react-dom
为“外部材料”,因为我不不希望他们被捆绑在我的图书馆中,可以安全地承担任何项目将使用这个项目也将有reactjs
。
我该如何处理可能存在或不存在于使用该库的任何项目中的其他第三方库?我是否应该排除捆绑中的所有第三方库,如果有,如何确保项目正在使用我的库可以找到它们?
你使用哪个版本的'webpack' – Aaqib
webpack版本3.5.6 – CSharp