Prevent Meteor from wrapping scripts in an immedia

2019-07-15 07:20发布

问题:

Meteor will wrap an immediately-invoked function expression (IFFE) around the contents of any JS file, to ensure that there are no namespace conflicts between files.

I am at the very early stage of a project which uses a beta npm module. I would like to be able to run code directly from the browser console, which has global scope.

Is there a way to ask Meteor nicely not to wrap all my scripts in an IFFE, so that I can create global functions and access global variables, and so understand more easily what the beta npm module is doing (and what it is doing wrong)?

Thanks in advance.

回答1:

If your code is running on the client side, you can simply put it into the client/compatibility folder. From the meteor docs (http://docs.meteor.com/#/full/structuringyourapp):

client/compatibility

This folder is for compatibility JavaScript libraries that rely on variables declared with var at the top level being exported as globals. Files in this directory are executed without being wrapped in a new variable scope. These files are executed before other client-side JavaScript files.