Polymer / tools

Polymer Tools Monorepo
BSD 3-Clause "New" or "Revised" License
430 stars 200 forks source link

[bundler] Rollup sorting affects imports order #802

Open web-padawan opened 6 years ago

web-padawan commented 6 years ago

Description

In Vaadin we use a ThemableMixin allowing to inject styles into custom elements via snippets <dom-module id="style-name" theme-for="component-name">. It is done by overriding finalize static method.

So, we assume the order of the scripts execution to ensure the theme modules are added to the DOM before the customElements.define is called for the same tag name. In Polymer 3 it looks like this:

import './vaadin-button-styles.js';
import '../../src/vaadin-button.js';

However, after running polymer build on a small project (which only has shell and no fragments, with a few components), the order of scripts in resulting output is reversed:

  _exports.TextFieldElement = TextFieldElement;
  customElements.define(TextFieldElement.is, TextFieldElement);
  var vaadinTextField = {
    TextFieldElement: TextFieldElement
  };
  _exports.$vaadinTextField = vaadinTextField;
  const $_documentContainer$8 = html`<dom-module id="lumo-text-field" theme-for="vaadin-text-field">
  <template>
  <!-- styles --> 
  </template>
</dom-module>`;

Tested this with a sample project using 2 components: text-field and button, both separately and together. Same happens when importing Material versions of components.

Steps to reproduce

  1. Clone the repo
    git clone https://github.com/web-padawan/vaadin-text-field-theming-issue && cd vaadin-text-field-theming-issue
  2. Install dependencies
    npm install
  3. Run the build
    npm run build
  4. Serve the output
    polymer serve build/es6-bundled
  5. See the components without style modules applied

Originally reported at vaadin/vaadin-themable-mixin#36

web-padawan commented 6 years ago

@usergenic IIRC you have been working on certain rollup workarounds. Have you noticed something similar to this issue, and do you have any idea what could happen and how do we investigate?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

web-padawan commented 4 years ago

This issue is quite annoying, it would be nice to get it fixed. However, it's less important for us at the moment, because in Vaadin we switched to npm using webpack as a default bundler.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.