-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get individual ES6 module loading to work as per wiki page #381
Comments
I don't know how to work out this dependency yet. The point is to create custom builds and everything is working fine, so perhaps you want to work your way with custom builds? Either way, perhaps making sure you have it's dependencies installed and importing into your ES6 file? I'm also open to any suggestions. |
Also thanks for the wiki edit, you probably tested it, I wrote a quick wiki update to rush the release.. |
The problem with the code that's there right now is that browsers don't support bare import specifiers like If I assume
After relativizing all the import paths in the current sources like that, I can then do:
...and it works. So I can think of a few options:
I'd probably take the last approach. It looks as if
will build an all-in-one ES6 module version of shorter-js, so you could have a step to do that and dump it into the |
What if I produce a module for each component, similar cu what Bootstrap does? Your |
Including Or I guess you could rollup the necessary |
You think we should remove |
Could be worth looking into. For example, native |
I agree about classes. Are you deploying something like a bundle by any chance? I'm thinking maybe installing the dependency and importing it along would help solve the problem? |
I am considering a future plan to rework this stuff, removing dependency on class and event delegation, but there are some little things that keep repeating over and over. On the issue at hand, do you have a definite plan to solve this issue without creating custom builds? |
Right now my application is in early development. I don't have a bundler — it's a Go application with minimal front-end vanilla JavaScript — but the build process preminifies and precompresses everything. My plan so far is to just import the whole of I really opened the ticket to alert you that the individual module loading doesn't work at present, and maybe help fix that if there's a way to do it without breaking the existing build process. |
You're very safe to work with custom builds, it's so easy, you just don't care. |
Not sure what you are getting at there? Anyway, looks like the easiest option is to build standalone ES6 modules by rolling in
Those can then be loaded as modules. So maybe that's what the wiki page should suggest. |
Even better, you can do trunk> $
npm run custom INPUTFILE:src/components/button.js,OUTPUTFILE:dist/button.esm.js,MIN:false,FORMAT:esm I think browsers should be able to handle this dependency handling in the future. |
Perfect! Updated the wiki page. |
Thank you :) |
* changed all util and imports structure for more accurate bundles * addressing #381, added more build scripts, now `dist/components/` folder holds UMD and ESM modules for all components, @lpar can have a look? * removed dependency on `shorter-js` for events handling, class manipulation, and more, see commit file changes
@lpar please check latest master, I've update the wiki accordingly, please confirm we're all right :) |
Checked and the distributed ESM build of modal-native in dist/components works, that's the one I need so far. I assume if that works the others will. |
@lpar I'm making a custom build tool
var Button = require "dist/components/button-native.js" you basically expect it to work with var btn = new Button('selector') and not var btn = new BSN.Button('selector') correct? |
@lpar I've updated the code, if you check my last commit you will understand. Basically now you can do |
I'm afraid I've not used UMD or CJS client side. Until ES6 modules were standardized I just used revealing module pattern via IIFE in my client-side code, so that I didn't have to adopt a whole transformation toolchain. Looks like you've got a bad path in
The file is actually named Using the IIFE version you'll still end up with a single
I can then do:
and it works. I assume that would work for UMD format too. |
I've updated the file name, will release a new version as soon as I can. I think in the end it's up to you to create your own files and own formats, I've put up the tools for you to easily work it out. |
@lpar I've made a new build script
In addition you can specify a destination via OUTPUTFILE, by default the destination is |
@lpar are we good to close this once and for all? |
According to the wiki, you can import only the individual modules you want using ES6 imports. e.g.
However,
button-native.js
depends onshorter-js
:I can't work out how to get those import paths to work, even for a local deployment, so the browser just gives me
TypeError: Error resolving module specifier: shorter-js/src/class/hasClass.js
.Similarly, I can import the whole thing from the CDN via:
But the corresponding single-module import doesn't work:
Same problem -- can't resolve the
shorter-js
dependency.Is there a build or deploy process I need to go through first to get individual ES6 components to work?
The text was updated successfully, but these errors were encountered: