-
Notifications
You must be signed in to change notification settings - Fork 150
Chaining scss and postcss produces unexpected results #115
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
Comments
Hey @rbnlffl 👋 Just tried your configs in the Can you test it? |
Thanks for taking the time, man! Your example works. After some investigation, I know where the problem lies—it's the <style global lang="scss">
:root {
--color-white: #fff;
--color-black: #000;
--color-shadow: rgba(0, 0, 0, .1);
--color-text: #606060;
--color-brand: #67bf66;
--color-brand-muted: #67bf669a;
--font-weight-light: 300;
--font-weight-regular: 400;
--font-weight-bold: 600;
}
*,
*::after,
*::before {
box-sizing: border-box;
}
html {
font-family: Inter, system-ui;
font-size: 110%;
line-height: 1.6;
color: var(--color-text);
}
body {
margin: 0;
}
#app {
display: flex;
flex-direction: column;
align-items: center;
}
</style> Now, when I run my code as I did before, the ouput for, let's say html {
font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
font-size: 110%;
line-height: 1.6;
color: var(--color-text);
} If I move html {
font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
font-size: 110%;
line-height: 1.6;
color: #606060;
color: var(--color-text);
} Interesting. But now, lets look at another component, trying to access the variables exposed in <style lang="scss">
a {
display: inline-block;
color: inherit;
}
.primary,
.secondary,
.ghost {
color: var(--color-white);
position: relative;
border-radius: 10px;
padding: 15px 25px;
text-decoration: none;
font-size: .8rem;
font-weight: var(--font-weight-bold);
text-shadow: none;
&::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
opacity: 0;
transition: opacity .3s ease-in-out;
}
&:hover {
&::after {
opacity: 1;
}
}
}
.primary {
background-color: var(--color-brand);
}
.ghost {
background-color: var(--color-brand-muted);
}
.navigation {
position: relative;
padding: 30px;
text-decoration: none;
&::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 5px;
background-color: var(--color-brand-muted);
transform: scaleY(0);
transition: transform .3s ease-in-out;
transform-origin: bottom;
}
&:hover {
&::after {
transform: scaleY(1);
}
}
}
</style> The output there is, for example: .primary.svelte-1lyn5rv, .secondary.svelte-1lyn5rv, .ghost.svelte-1lyn5rv {
color: var(--color-white);
position: relative;
border-radius: 10px;
padding: 15px 25px;
text-decoration: none;
font-size: .8rem;
font-weight: var(--font-weight-bold);
text-shadow: none;
} So I guess the issue is with |
Hmmm, I have to check what's happening. Would you be able to provide a repro with these components + your configs? Currently, the |
For sure, here you go: https://github.com/rbnlffl/agricontrol/tree/svelte |
After testing it a bit, it seems the I'll add a note about this to the readme |
Alright, doing this doesn't completely fix the problem, though. While html {
font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
font-size: 110%;
line-height: 1.6;
color: #606060;
color: var(--color-text);
}
.primary.svelte-1lyn5rv, .secondary.svelte-1lyn5rv, .ghost.svelte-1lyn5rv {
color: var(--color-white);
position: relative;
border-radius: 10px;
padding: 15px 25px;
text-decoration: none;
font-size: .8rem;
font-weight: var(--font-weight-bold);
text-shadow: none;
} For now, I can get arount this by having a |
That's happening because preprocessed files don't communicate with each other nor have a shared context. Svelte and the preprocessors (postcss) don't know anything about those |
I agree—in theory, this should solve it. But sadly, changing my rollup config to the following produces the exact same result as in my previous reply: /* eslint-env node */
import svelte from 'rollup-plugin-svelte';
import babel from 'rollup-plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import browsersync from 'rollup-plugin-browsersync';
import postcss from 'rollup-plugin-postcss';
import preprocess from 'svelte-preprocess';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import cssEnv from 'postcss-preset-env';
const dev = process.env['dev'] === 'true';
const buildOnly = process.env['build-only'] === 'true';
export default {
input: 'src/app.js',
output: {
sourcemap: dev,
format: 'iife',
name: 'agricontrol',
file: 'public/app.js'
},
plugins: [
resolve(),
commonjs(),
svelte({
dev: dev,
preprocess: preprocess(),
emitCss: true
}),
postcss({
extract: true,
sourcemap: dev,
plugins: [
cssEnv(),
!dev && autoprefixer(),
!dev && cssnano()
].filter(plugin => plugin)
}),
!dev && babel({
extensions: [ '.js', '.mjs', '.svelte' ],
include: [ 'src/**', 'node_modules/svelte/**' ],
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}]
]
}),
!dev && terser(),
!buildOnly && browsersync({
server: 'public',
notify: false,
ui: false
})
].filter(plugin => plugin)
}; |
There's a possibility that the generated css file is not passing through Possibly related PR: sveltejs/rollup-plugin-svelte#72. You could run |
Describe the bug
When using
scss
andpostcss
inside of thepreprocess
array ofrollup-plugin-svelte
, PostCSS only seems to perform some, but not all, desired transformations. What I meant by this is that while, for example,font-family: Inter, system-ui;
correctly gets transformed tofont-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
,color: var(--color-text);
does not get transformed tocolor: #fff;
. This then results in the app not rendering correctly in IE. https://int.agricontrol.app/svelte/To Reproduce
This is my
rollup.config.js
:Then, for example, the
style
tag of my mainLink.svelte
:My
package.json
:Expected behavior
What I expect to happen is for
scss
to perform the transpiling, like resolving nestings and such, and then forpostcss
to perform the polyfilling.Information about your project:
Your browser and the version: Firefox Developer Edition, v73.0
Your operating system: macOS 10.15.3
svelte-preprocess
version: 3.4.0Whether your project uses Webpack or Rollup: Rollup, v1.31.0
The text was updated successfully, but these errors were encountered: