简体   繁体   English

解决webpack中的别名

[英]Resolving alias in webpack

I am trying to resolve an alias in webpack but can't seem to figure out why this isn't working. 我正在尝试解析webpack中的别名,但似乎无法弄清楚为什么它不起作用。 I am using a library called GoJS. 我正在使用一个名为GoJS的库。 I have the below code in my module.exports of webpack: 我在webpack的module.exports中包含以下代码:

resolve: {
        alias: {
            go: path.resolve(__dirname, './go.min.js')
        }
    }

This file is in my root project directory for now. 该文件现在位于我的根项目目录中。 At the top of my ES6 module I have: 在我的ES6模块的顶部,我有:

import go from 'go';

I have also tried: 我也尝试过:

var go = require("go");

The library does seem to be loading. 该库似乎正在加载。 If I console.log(go) within the module, it returns an empty object. 如果我在模块内进行console.log(go),它将返回一个空对象。 Do I need to load this file a different way because of how it is designed? 由于其设计方式,我是否需要以其他方式加载此文件? Or is something wrong with my webpack settings? 还是我的Webpack设置有问题?

Here is the javascript file I am trying to load 这是我要加载的JavaScript文件

这可以通过将GoJS更新到更高版本(可能是1.5或更高版本)来解决,因为此后它会以不同的方式处理模块/需求/导入。

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

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