NewDevelop NewDevelop - 2 months ago 9
Node.js Question

how to change baseUrl path in init.js

I need to define a nodejs library (from

pr_name/node_modules/lib_name
). At my
pr_name/static/js/init.js
file I defined a
baseUrl
path:

baseUrl: 'static',


then I defined some
paths
at static dir. How can I add the node library from different path?

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
}


Upd.

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


and

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


both gives me an error at browser console.

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


where export-stats has an xlsx-chart require:

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


I can't understand the source of problem.

Upd.Upd.
Now I understand - my site is
python
's and all of used urls must be defined at
urls.py
. And
'xlsx-chart'
goes to its own url like same
node.js
-library.

Answer

Depending on how the server that serves your data is configured, you could use an absolute path:

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

If node_modules is not at the root of what the server serves, a relative path can also work and perhaps be nicer in some cases:

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

I've used both.

Comments