modules within the page

17 views
Skip to first unread message

Perry Smith

unread,
Jan 18, 2016, 9:50:26 AM1/18/16
to Exploring ES6
I have a use case where an external program produces an html file that has css and javascript in it.  The page shows a diagram of a computer network using various data files as its input.

I'd like to use modules (eventually) but the way things are phrased I'm afraid I won't be able to.   Your books says that there is one module per file and one file per module.

In my case, the output file is self contained and does not refer to any external entities.  This is so the html file can be moved around and it still works.  This means that the javascript code pieces are within script tags without a src attribute.  Is there a method to make these modules and leverage the beauty of import and export? 

In other words, is there a way to attach a "file" (or a file name) to the javascript code embedded within a script tag?  For example when I say "import from 'module1';"  module1 isn't somewhere out on the net but is within the html file already.

This may be more of a browser implementation question than a javascript question but I thought I would ask here first hoping this use case has already been discussed at some point.

Thank you for your time,
Perry

Reply all
Reply to author
Forward
0 new messages