Skip to content

Instantly share code, notes, and snippets.

@romeovs
Last active December 1, 2020 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romeovs/34586f19fa378a95b1d6a15538a98dc2 to your computer and use it in GitHub Desktop.
Save romeovs/34586f19fa378a95b1d6a15538a98dc2 to your computer and use it in GitHub Desktop.
This codebase shows that there are ordering issues in rollup-plugin-styles

rollup-plugin-styles order discrepancies

This gist shows that there are ordering issues in rollup-plugin-styles. The output is different based on what mode is being used. The extract output is out of order.

To test run:

yarn
yarn build

and open inject.html and extract.html to see the difference.

<!doctype html>
<html>
<head>
<script src="./dist/extract/index.js"></script>
<link rel="stylesheet" href="./dist/extract/index.css" />
</head>
<body>
<div class="foo">
This should be red.
</div>
</body>
</html>
.foo {
color: blue;
}
import css from './foo.css'
export const foo = css
.foo {
color: red;
}
import { foo } from './foo'
import css from './index.css'
console.log('Hello world!')
<!doctype html>
<html>
<head>
<script src="./dist/inject/index.js"></script>
</head>
<body>
<div class="foo">
This should be red.
</div>
</body>
</html>
{
"name": "example-style-order",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"build": "rollup -c && echo 'Open inject.html and extract.html to see the difference'"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^11.0.0",
"rollup": "^2.34.0",
"rollup-plugin-styles": "^3.11.0"
}
}
import resolve from '@rollup/plugin-node-resolve'
import styles from 'rollup-plugin-styles'
function config(mode) {
return {
input: './src/index.js',
output: {
dir: `dist/${mode}`,
entryFileNames: '[name].js',
assetFileNames: '[name].[ext]',
},
plugins: [
resolve(),
styles({
mode,
}),
],
}
}
export default [
config('inject'),
config('extract'),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment