我有一个小型实用程序项目,我正在使用反应引导表。我正在使用 webpack 将这个项目捆绑到一些不同的项目中。我的 webpack 配置文件是这样的。当我在导入实用程序包的主项目中运行 gulp 时;我收到以下错误。
Error: Cannot find module 'jquery' from 'C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\src\javascript\components\dnsIpam'
at C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:46:17
at process (C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:173:43)
at ondir (C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:188:17)
at load (C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:69:43)
at onex (C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:92:31)
at C:\Users\sunny.bogawat\Workspace\Projects\viewpoint_ui_sunny\node_modules\browser-resolve\node_modules\resolve\lib\async.js:22:47
at FSReqWrap.oncomplete (fs.js:82:15)
webpack 配置文件
const path = require('path');
var webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var build = 'dns-ipam';
// shared config settings
var config = {
module: {
loaders: [
{ test: /.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.(less|css)$/, loader: ExtractTextPlugin.extract('style-loader',
'css-loader!less-loader') },
{ test: /\.(png|jpg|gif|jpeg|svg)$/,
loader: 'file?name=images/[name].[ext]' },
{ test: /\.(ttf|woff|eot|otf)$/,
loader: 'file?name=fonts/[name].[ext]' },
{ test: /\.json$/,
loader: 'json' },
],
},
output: {
path: path.join(__dirname, 'dist'),
filename: `${build}-react-components.js`,
library: `${build}-react-components`,
libraryTarget: 'umd',
},
plugins: [
new ExtractTextPlugin(`${build}-react-components.css`),
new webpack.ProvidePlugin({$: 'jquery', jQuery: 'jquery',}),
],
externals: [{
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
}, {
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
}],
};
// custom config settings
config.entry = './src/components/dns-ipam-index.js';
// if (build == 'dns-ipam') {
// config.plugins.push(new webpack.optimize.UglifyJsPlugin({
// compress: { warnings: false },
// }));
// }
module.exports = config;