Sitelet https://web.archive.org/web/20210723025837/https://github.com/duetds/date-picker/issues/22
Skip to content
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

Bundling @duetds/date-picker with Rollup doesn't work #22

Open
sto3psl opened this issue Sep 22, 2020 · 6 comments
Open

Bundling @duetds/date-picker with Rollup doesn't work #22

sto3psl opened this issue Sep 22, 2020 · 6 comments

Comments

@sto3psl
Copy link

@sto3psl sto3psl commented Sep 22, 2020

Describe the bug
Currently @duetds/date-picker does not work with Rollup (or I didn't get it to).
The problem appears to be a dynamic import statement with a template string:

return import(`./${bundleId}.entry.js${""}`);

Rollup seems to ignore these imports: "Dynamic imports on runtime are ignored by Rollup #2463"

To Reproduce
Clone this repository https://github.com/sto3psl/rollup-duet-date-picker and follow the steps to create a bundle.

Expected behavior
<duet-date-picker></duet-date-picker> should render in the browser with no errors.

Desktop (please complete the following information):

  • OS: macOS 10.15.6
  • Browser: all of them

I'm not sure if this problem comes through duetds/date-picker or Stencil.js or the way everything is published.

@sto3psl
Copy link
Author

@sto3psl sto3psl commented Sep 22, 2020

My current workaround is a custom Rollup plugin that directly resolves the template string import like this:

// rollup.config.js

export default {
  ...
  plugins: [
    {
      resolveDynamicImport(specifier, importer) {
        // match file with "bad" import
        const matches = !!importer.match(
          /@duetds\/date-picker\/dist.*\/index-/g
        );

        if (typeof specifier === "string" || !matches) return null;

        // resolve to static file, which will add it to the rollup bundle
        return this.resolve(
          "@duetds/date-picker/dist/esm/duet-date-picker.entry.js"
        );
      }
  ]
}
@WickyNilliams
Copy link
Contributor

@WickyNilliams WickyNilliams commented Sep 24, 2020

Thanks for the detailed report!

Can you try instead importing @duetds/date-picker/custom-element? That's the import intended for use with a bundler (docs are not clear on this admittedly). Though it's possible I still need to tweak the build to inline dynamic imports. If it doesn't work, let me know, and I'll fix it!

@sto3psl
Copy link
Author

@sto3psl sto3psl commented Sep 25, 2020

Well, that works flawlessly! Thanks @WickyNilliams!

I updated my repository and added a note with the "fix" if anyone else runs into this issue. I think it would be great to make it more clear in the docs that the single file bundle is supposed to be used with bundlers and that it also exports defineCustomElements.

@WickyNilliams
Copy link
Contributor

@WickyNilliams WickyNilliams commented Sep 28, 2020

Yeah, I'll update the docs in next batch of changes to be more clear about this. Also I can tweak that specific build to also have no dynamic imports, or dependencies at all. Just a single flat file. Should work in even more environments that way

@sto3psl
Copy link
Author

@sto3psl sto3psl commented Sep 28, 2020

As far as I could tell, @duetds/date-picker/custom-element didn't have dynamic imports. Thanks for your quick help!

@sto3psl sto3psl closed this Sep 28, 2020
@WickyNilliams
Copy link
Contributor

@WickyNilliams WickyNilliams commented Sep 28, 2020

I'll reopen this to track the docs changes :)

It indirectly contains a dynamic import, as it statically imports @stencil/core/internal, which itself contains a dynamic import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants