I would like to load non-AMD modules (jQuery and blockUI) using @NAmdConfig for client script, but my code occurs error in browser.
Uncaught Error: Module does not exist: ../../lib/jquery-blockUI.js
If I use absolute path instead of relative path, it works.
"baseUrl": "../../lib/"
Replace above with below, then works.
"baseUrl": "/SuiteScripts/ComponentA/SuiteScript2/lib/"
However I would like to use relative path because these scripts are going to be released as a bundle.
My current solution for this issue is using absolute path and replacing the path with bundle path when I release a bundle.
Does anyone know how to use relative path or better solution?
Script Files
File Structure
SuiteScripts/
└── ComponentA/
└── SuiteScript2/
├── FunctionA/
│ ├ config.json
│ ├ Suitelet.js
│ └ ClientScript.js
└── lib/
├ jquery.min.js
└ jquery-blockUI.js
config.json
{
"baseUrl": "../../lib/",
"paths": {
"jquery": "jquery.min.js",
"blockUI": "jquery-blockUI.js"
},
"shim": {
"blockUI": ["jquery"]
}
}
Suitelet.js
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
* @NAmdConfig ./config.json
*/
define(['N/record', 'N/url', 'N/ui/serverWidget'],
function(record, nsUrl, serverWidget) {
function onRequest(context) {
// code abbreviated
var form = serverWidget.createForm({title: 'FunctionA', hideNavBar: false});
// Set client script
form.clientScriptModulePath = './ClientScript.js';
// code abbreviated
}
})
ClientScript.js
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
* @NAmdConfig ./config.json
*/
define(['N/runtime', 'N/url', 'blockUI'],
function (runtime, url, blockUI) {
// code using blockUI
});