我正在努力想办法把这个javascript包含在webpack的代码中,但我还在苦苦挣扎。我正在通过npm安装一个名为angular-colorthief的angular模块。我已经安装了它,并将该模块包含在我的webpack配置文件中:
if(TEST) {
config.entry = {};
} else {
config.entry = {
app: './client/app/app.js',
polyfills: './client/polyfills.js',
vendor: [
'angular',
'angular-colorthief',
'angular-animate',
'angular-aria',
'angular-cookies',
'angular-resource',
'angular-route',
'angular-sanitize',
'angular-socket-io',
'angular-material',
'lodash'
]
};
}问题是angular -color目录中有另一个js,angular模块依赖这个js,这个js叫做color-thief.js。此文件不会导出任何内容。angular-colorthief模块以这种方式需要它:
use strict';
require("./color-thief");
angular.module('ngColorThief', [])
.provider('$colorThief', [function () {当我运行我的应用程序时,我一直收到ColorThief未定义的错误,因为尽管此脚本包含在我的供应商捆绑包中,但在angular模块运行时它不可用。有人能帮我解决这个问题吗?我已经尝试安装exports-loader模块,但是我不确定如何使用它来解决这个问题。这是我试图添加的加载器,但这不起作用。
{
include: require.resolve("./color-thief"),
loader: "exports?ColorThief!node_modules/angular-colorthief/color-thief.js"
}发布于 2016-08-08 11:40:19
所以我不确定这是否是正确的解决方案,但它解决了我的问题。如果有人能告诉我一个更好的方法,我将不胜感激。对于其他任何人,这是我最终添加到我的加载器中的内容。
{
include: require.resolve(path.resolve(__dirname, 'node_modules/angular-colorthief/color-thief.js')),
loader: "exports?ColorThief"
}, {
include: require.resolve(path.resolve(__dirname, 'node_modules/angular-colorthief/angular-colorthief.js')),
loader: "imports?ColorThief=./color-thief.js"
}https://stackoverflow.com/questions/38816010
复制相似问题