0

I have a single page app which comprises of a JS bundle based on Browserify and Coffeescript.

In a certain usecase, I need to create an adhoc page (Detached from the SPA) which needs to access a library (Kendo to be specific), which is part of the browserified bundle and the adhoc page would have some simple JS based on kendo.

The question is how do I load/access the library outside the Single Page Application (If I try loading it, the browser says that the library is not found)?

Using RequireJS could be an option as specified here. But, I dont want to use another library just for this purpose. I think there must be a way to "require" the library without requireJS because it is already working in the Single Page Application.

Please help.. Thanks!

1 Answer 1

1

Browserify rewrites your module paths like ../moduleA/file.js into an internal module id like 23 when packing.

Every require statement will also be rewritten, a statement like this:

var moduleA = require('../moduleA/file.js');

Becomes this:

var moduleA = require(23);

To get access to a particular library, you can do to things:

1) find the internal id via debugger and then require the module via it (this is quite fragile, because the internal id could change with every build) 2) package another file into your bundle with the following contents:

var kendo = require('kendo');
window.kendo = kendo;

Afterwards, you can simply access kendo as a page global.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.