Skip to content

Sort extracted styles according to module order - #109

Closed
dnjstrom wants to merge 3 commits into
egoist:masterfrom
dnjstrom:bug-extract-order
Closed

dnjstrom wants to merge 3 commits into
egoist:masterfrom
dnjstrom:bug-extract-order

Conversation

@dnjstrom

@dnjstrom dnjstrom commented Jun 1, 2018

Copy link
Copy Markdown
Contributor

Heavily guided by the reference-implementation by danburzo in #96 these changes correct the source ordering of the extracted styles in the minimal example from #108 and my original project.

@codecov

codecov Bot commented Jun 1, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #109 into master will decrease coverage by 0.72%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #109      +/-   ##
==========================================
- Coverage    95.1%   94.37%   -0.73%     
==========================================
  Files           8        8              
  Lines         245      249       +4     
  Branches       84       85       +1     
==========================================
+ Hits          233      235       +2     
- Misses         12       14       +2
Impacted Files Coverage Δ
src/index.js 96.29% <60%> (-2.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d1ec84...dc7d5df. Read the comment docs.

@dnjstrom

dnjstrom commented Jun 2, 2018

Copy link
Copy Markdown
Contributor Author

The bundle parameter of onWrite is different in the tests from what I see in actual usage in that it's missing the imports, exports and modules properties no matter what configuration I try. Maybe I'm missing something or maybe there's some difference in the test setup to actual use that's causing the discrepancy?

Logging out the bundle gives me the following:

Test bundle (modules > extract)

{
  code: '\'use strict\';\n\nvar css = {shouldBeOverridden:bar_shouldBeOverridden};\n\nvar second = {shouldOverride:style_shouldOverride};\n\nconsole.log(first, css.shouldBeOverridden);\nconsole.log(second, second.shouldOverride);\n',
  map: undefined
}

Actual use bundle (minimal example)

{
  imports: [],
  exports: [],
  modules:
   [ '/extract-css-source-order/src/some-component/styles.css',
     '/extract-css-source-order/src/some-component/index.js',
     '/extract-css-source-order/src/styles.css',
     '/extract-css-source-order/src/index.js' ],
  code: 'const css = {};\n\nconst element = document.createElement(div);\nconst text = document.createTextNode(This should be green);\nelement.appendChild(text);\nelement.classList.add(css.shouldBeOverriden);\n\nconst css = {};\n\nconst element = element;\nelement.classList.add(css.shouldOverride);\n\ndocument.getElementById(root).appendChild(element);\n',
  map: null }

@dnjstrom

Copy link
Copy Markdown
Contributor Author

Any thoughts on the above @egoist? :)

@dnjstrom

dnjstrom commented Jul 3, 2018

Copy link
Copy Markdown
Contributor Author

Would really appreciate some help here @egoist 🙂

@mycarrysun

mycarrysun commented Jul 10, 2018 •

Copy link
Copy Markdown

Thanks for digging into this @dnjstrom! I am having the same problem. I have a single file where all of my style imports are imported and the order of the imports do not seem to affect the compiled output.

Import order in index.js

import './vendor/quasar/dist/quasar.mat.css'
import 'quasar-extras/roboto-font'
import 'vue-datetime/dist/vue-datetime.min.css'
import './styl/styles.styl'
import './scss/styles.scss'

Compiled output order

styles.styl
styles.scss
quasar.mat.css
vue-datetime.min.css
roboto-font.css

@mycarrysun

Copy link
Copy Markdown

/ping @egoist

@channg

channg commented Aug 31, 2018

Copy link
Copy Markdown

ping @egoist

@wuweiweiwu

Copy link
Copy Markdown

BUMP @egoist

maybe its time someone forks this and republishes

christophehurpeau added a commit to christophehurpeau/rollup-plugin-postcss that referenced this pull request Oct 17, 2018
christophehurpeau added a commit to christophehurpeau/rollup-plugin-postcss that referenced this pull request Oct 17, 2018
christophehurpeau added a commit to christophehurpeau/rollup-plugin-postcss that referenced this pull request Oct 17, 2018
@GreenGremlin

GreenGremlin commented Nov 28, 2018 •

Copy link
Copy Markdown

It looks like this may have been fixed in rollup.

Version 0.63.5

@GreenGremlin

Copy link
Copy Markdown

I can confirm, upgrading to the latest version of rollup fixes this for me, even with the mainline release of rollup-plugin-postcss.

@dnjstrom

dnjstrom commented Dec 2, 2018

Copy link
Copy Markdown
Contributor Author

@GreenGremlin: I'm afraid that issue is different from what this PR aims to address. The issue you linked deals with the execution order of different successive plugins, while this pr is only concerned with the generated style order produced by rollup-plugin-postcss even without any other plugins present.

I've updated my minimal example project with the latest rollup and rollup-plugin-postcss packages and the order issue is clearly still present.

@kendrickw

kendrickw commented Dec 14, 2018 •

Copy link
Copy Markdown
Contributor

@dnjstrom , I've taken the liberty to fix the code coverage issue this PR encountered in another PR #143. Please review.

@egoist

egoist commented Jan 22, 2019

Copy link
Copy Markdown
Owner

Fixed in another PR, thanks everyone.

@egoist egoist closed this Jan 22, 2019
@dnjstrom
dnjstrom deleted the bug-extract-order branch January 23, 2019 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants