使用requires-config.js

时间:2016-09-13 10:40:16

标签: magento-2.0

我创建了一个自定义模块并添加了requires-config.js(app \ code \ Namespace \ Modulename \ view \ frontend)。

var config = {
map: {
    '*': {
        test: 'https://example.com/test.js'
    }
}

};

之后我部署了静态内容,现在我可以看到外部js已添加到以下位置(pub \ static_requirejs \ frontend \ Magento \ luma \ en_US),但仍然没有在页面源中加载外部js(使用安慰)。 我还需要在布局中添加js文件吗?

<head>
    <link src="https://example.com/test.js"/>
</head>

1 个答案:

答案 0 :(得分:0)

将js放在 Modulename / view / frontend / web / js 文件夹中而不是从网址加载是一种很好的做法。

var config = {
    "map": {
        "*": {
            "test": "Modulename/js/test"
        }
    }
};

此外,您不需要在require js文件中添加.js扩展名。 然后检查它会加载

请清除缓存并执行静态内容部署

相关问题