那很奇怪,但它确实发生了。我试图使用从凉亭安装的KUTE.js,这里是配置:
webpack config:
var webpack = require("webpack");
module.exports = {
entry: './src/main.js',
output: {
path: './dist',
filename: 'bundle.js'
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.ttf$/, loader: 'file?name=dist/[name].[ext]' },
{ test: require.resolve('zepto'), loader: 'imports?this=>window' },
{ test: require.resolve('KUTE.js'), loader: 'imports?this=>window!expose?KUTE' },
],
plugins: [
new webpack.ProvidePlugin({
KUTE: "KUTE.js"
})
]
},
resolve: {
modulesDirectories: ['node_modules', 'bower_components', 'web_modules']
}
};
我在src / main.js中需要代码:
require(['zepto', 'KUTE.js', 'KUTE.js/kute-svg'], function() {...});
我需要这个插件,它取决于KUTE global。问题是,当我注释掉相关的加载器和测试解析(加载器中的第3行)时,webpack编译捆绑很好,但由于缺少全局而无法加载插件。如果我保持原样,我会收到标准错误:
module.js:327
throw err;
^
Error: Cannot find module 'KUTE.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.require.resolve (internal/module.js:16:19)
at Object.<anonymous> (/storage/demo/words/webpack.config.js:14:23)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at module.exports (/usr/lib64/node_modules/webpack/bin/convert-argv.js:80:13)
同时:
$ ls bower_components
KUTE.js
怎么可能?