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

Using the :global(...) CSS selector causes an error when using Sass's indented syntax. #2920

Closed
elliotwaite opened this issue Jun 1, 2019 · 2 comments

Comments

@elliotwaite
Copy link
Contributor

Trying to use the css global selector (:global(...)) causes a syntax error when trying to use Sass's indented syntax.

Here is the code to reproduce the issue (adapted from the sveltejs/template).

App.svelte:

<style type="text/sass">
:global(h1)
  color: purple
</style>

<h1>Hello world!</h1>

Then this was added to rollup.config.js:

import { sass } from 'svelte-preprocess-sass';
...
svelte({
  ...
  preprocess: {
    style: sass({indentedSyntax: true}),
  },
  ...

The full rollup.config.js:

import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import { sass } from 'svelte-preprocess-sass';

const production = !process.env.ROLLUP_WATCH;

export default {
  input: 'src/main.js',
  output: {
    sourcemap: true,
    format: 'iife',
    name: 'app',
    file: 'public/bundle.js'
  },
  plugins: [
    svelte({
      // enable run-time checks when not in production
      dev: !production,
      preprocess: {
        style: sass({indentedSyntax: true}),
      },
      // we'll extract any component CSS out into
      // a separate file — better for performance
      css: css => {
        css.write('public/bundle.css');
      }
    }),

    // If you have external dependencies installed from
    // npm, you'll most likely need these plugins. In
    // some cases you'll need additional configuration —
    // consult the documentation for details:
    // https://github.com/rollup/rollup-plugin-commonjs
    resolve(),
    commonjs(),

    // Watch the `public` directory and refresh the
    // browser on changes when not in production
    !production && livereload('public'),

    // If we're building for production (npm run build
    // instead of npm run dev), minify
    production && terser()
  ],
  watch: {
    clearScreen: false
  }
};

Error message:

Error: Invalid CSS after "": expected 1 selector or at-rule, was "global(h1): {"

Any suggestions for how to fix this issue?

@elliotwaite elliotwaite changed the title Using the :global(...) css selector causes an error when using Sass's indented syntax. Using the :global(...) CSS selector causes an error when using Sass's indented syntax. Jun 1, 2019
@Conduitry
Copy link
Member

This doesn't sound like an issue with Svelte. I skimmed the linked svelte-preprocess-sass issue, and it sounds like the syntax just isn't valid indented sass. What specifically are you suggesting should happen?

@elliotwaite
Copy link
Contributor Author

elliotwaite commented Jun 2, 2019

Ah, you're right. Just found a solution that makes it valid sass syntax! Adding a backslash escape character \:global(...) makes it work.

<style type="text/sass">
\:global(h1)
  color: purple
</style>

Thanks for taking the time to look into this.

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

2 participants