繁体   English   中英

如何将Webpack与未导出的js一起使用

[英]How to use webpack with js that isn't exported

我试图弄清楚如何在webpack中包含这个javascript,但我很挣扎。 我正在通过npm安装一个名为angular-colorthief的角度模块。 我已经安装了它,并将模块包含在我的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-colorthief目录内部还有另一个js,Angular模块依赖于此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"
        }

所以我不确定这是否是正确的解决方案,但它解决了我的问题。 如果有人可以告诉我更好的方法,那我一定会很感激的。 对于其他人,这就是我最终添加到装载机中的内容。

{
          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"
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM