一个requirejs的坑

in cn •  6 years ago 

我加载模块的代码如下:

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'asset',
    paths: {
        vue: 'vue',
        comloader: 'comloader',
        comlist: 'comlist',
        text: 'text'
        com: 'components'
    }
});
require(["vue", "comloader", "comlist", "com/index"], function(Vue, comloader, comlist,js) {
    comloader.config(comlist, () => {
        setTimeout(() => {
            new Vue({
                el: "#app"
            });
        })
    })

})

我定义了一个com的path,然后我的目录中也有一个com文件夹,当我加载com文件夹下的模块时,路径替换为components。
为了避免冲突,我添加了一个path,修改如下:

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'asset',
    paths: {
        vue: 'vue',
        comloader: 'comloader',
        comlist: 'comlist',
        text: 'text'
        com: 'components',
        compath: 'com'
    }
});
require(["vue", "comloader", "comlist", "compath/index"], function(Vue, comloader, comlist,js) {
    comloader.config(comlist, () => {
        setTimeout(() => {
            new Vue({
                el: "#app"
            });
        })
    })

})
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!