Enterprise: General: Add default export so IDS-enterprise can be bundled

Created on 19 Apr 2020  路  6Comments  路  Source: infor-design/enterprise

Is your feature request related to a problem or use case? Please describe.
Currently using IDS-enterprise require you to include the assets in <script> tags.
And it will be available globally afterwards. There's no way to include it via ES6 import/syntax. Therefore you cannot use bundler such as Webpack to include IDS-enterprise

Describe the solution you'd like
Add default export, visible exports so components/functionalities from IDS-enterprise can be imported instead.

Describe alternatives you've considered
In my modified sohoxi.js I just added a default export, and it was enough for Webpack to recognize and bundle IDS-enterprise.

[5] type

Most helpful comment

I read the following article
https://levelup.gitconnected.com/code-splitting-for-libraries-bundling-for-npm-with-rollup-1-0-2522c7437697

So in the rollup.config file, I changed the value for property output to es
https://rollupjs.org/guide/en/#outputformat

With that build I can now use es6 import syntax to import things from IDS.
I could optionally add the imports to window.Soho so it can still be backward compatible for older users. Using the output format es also allow inclusion with <script type=module> for modern browsers. It is unfortunately not supported in IE11. But perhaps there are polyfills?

All 6 comments

In my custom fix I added the following line in the built sohoxi.js.

image

I read the following article
https://levelup.gitconnected.com/code-splitting-for-libraries-bundling-for-npm-with-rollup-1-0-2522c7437697

So in the rollup.config file, I changed the value for property output to es
https://rollupjs.org/guide/en/#outputformat

With that build I can now use es6 import syntax to import things from IDS.
I could optionally add the imports to window.Soho so it can still be backward compatible for older users. Using the output format es also allow inclusion with <script type=module> for modern browsers. It is unfortunately not supported in IE11. But perhaps there are polyfills?

Btw, lodash which we also are using has a version of it which they have built the library as ES modules
https://www.npmjs.com/package/lodash-es

So perhaps we could have a version of IDS which is built as ES modules, thus you can keep it backward compatible with the users which include IDS in <script> tags?

@guoliang agreed there, that's what I had been thinking when we first talked about this. I think we need to continue shipping a standard bundle that can be included in a script tag, and the ES6-module based bundle would be separate (but part of our distributable somehow).

Thanks for doing the digging on this!

Noting that as part of this issue, I'm going to upgrade Rollup from 2.10.x to 2.12.0

This issue is now resolved.

Was this page helpful?
0 / 5 - 0 ratings