如何在 init.js 中更改 baseUrl 路径

how to change baseUrl path in init.js

我需要定义一个 nodejs 库(来自 pr_name/node_modules/lib_name)。在我的 pr_name/static/js/init.js 文件中,我定义了一个 baseUrl 路径:

baseUrl: 'static',

然后我在静态目录定义了一些paths。如何从不同路径添加节点库?

require.config({
    baseUrl: 'static',
    paths: {
        'jquery': 'libs/jquery/dist/jquery.min',
        'jquery.maskedinput': 'libs/jquery.maskedinput/dist/jquery.maskedinput.min',
        'bootstrap': 'libs/bootswatch-dist/js/bootstrap.min',
        'xlsx-chart': '???' // <-- not at static but at node_modules
    }

更新

'xlsx-chart': '/node_modules/xlsx-chart/chart',

'xlsx-chart': '../node_modules/xlsx-chart/chart',

在浏览器控制台都给我一个错误。

require.js:165 Uncaught Error: Script error for "xlsx-chart", needed by: export-stats

其中 export-stats 有一个 xlsx-chart 要求:

define(['xlsx-chart'], function(XLSXChart){ 
....

我无法理解问题的根源。

Upd.Upd. 现在我明白了——我的站点是 python,所有使用的 url 必须在 urls.py 处定义。并且 'xlsx-chart' 进入它自己的 url 就像同一个 node.js-library。

根据为您的数据提供服务的服务器的配置方式,您可以使用绝对路径:

'xlsx-chart': '/node_modules/xlsx-chart'    

如果 node_modules 不是服务器服务的根目录,相对路径也可以工作,并且在某些情况下可能更好:

'xlsx-chart': '../node_modules/xlsx-chart'    

我都用过。