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

The order of imports #85

Open
mbursa opened this issue Jun 15, 2021 · 4 comments
Open

The order of imports #85

mbursa opened this issue Jun 15, 2021 · 4 comments

Comments

@mbursa
Copy link

mbursa commented Jun 15, 2021

Is there a way to control the order of css imports?

In my app.js I have:

import './assets/css/bootstrap.scss';

import layout_a from './layouts/layout-a.vue';  // contains <style> section
import layout_b from './layouts/layout-b.vue';
import page1 from './pages/page1.vue';
import page2 from './pages/page2.vue';

The output bundle css file contains first the <style> sections from all the vue files (in the order they are imported in app.js) and only then it contains bootstrap css. That of course is not good and bootstrap css has to go first so that scoped styles can override bootsrap rules if necessary.

My rollup.config.js looks like:

import vue from 'rollup-plugin-vue2';
import scss from 'rollup-plugin-scss';
// ...

export default {
    input: 'app.js',
    plugins: [
        vue(),
        scss({output: true}),
        // ...
    ],
};

Thanks.

@hultberg
Copy link

hultberg commented Jul 3, 2021

After a very quick skim of the code it seems this plugin will process all sass/scss before any css. You can import css files in sass with the @use rule (ref https://sass-lang.com/documentation/at-rules/use#loading-css). Hope this helps.

@emerxom
Copy link

emerxom commented Jul 23, 2021

After a very quick skim of the code it seems this plugin will process all sass/scss before any css. You can import css files in sass with the @use rule (ref https://sass-lang.com/documentation/at-rules/use#loading-css). Hope this helps.

I log the id before merging..
Is wrong the assumption that all scss are process before css,
is a for(key in object).

@emerxom
Copy link

emerxom commented Jul 23, 2021

I change the code to achieve wanna I wanted...

 // Combine all stylesheets
      let scss = ''
      let last = 'must-be-last'
      let lastId = null
      for (const id in styles) {
        console.log(id)
        if (id.includes(last)) lastId = id
        else scss += styles[id] || ''
      }
      scss += styles[lastId] || ''

In my option we should have options like

includeFirst:['thisOne.scss', 'thenThis'],
includeLater:['thenThisOne', 'thenThisLast'],

and the scss variable would merge first the id with included

  • values in the order they are given in the first array
  • all the other excluding the last array
  • values in the order they are given in the last array

@emerxom
Copy link

emerxom commented Jul 26, 2021

@thgh can you tag the issue as feature or something? 😀

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

No branches or pull requests

3 participants