5

I have this source file as src/mike.js

import '@ckeditor/ckeditor5-ui/theme/globals/globals.css'
export default function () {
    console.log('Hello world');
} 

@ckeditor/ckeditor5-ui/theme/globals/globals.css looks like this:

@import "./_hidden.css";
@import "./_reset.css";
@import "./_zindex.css";

And I have this rollup config:

import resolve from 'rollup-plugin-node-resolve';
import postcss from 'rollup-plugin-postcss'


export default {
    input: 'src/mike.js',
    output: {
        file: 'public/bundle2.js',
        format: 'cjs'
    },
    plugins: [resolve(), postcss({
        plugins: []
    })]
};

The rolled up public/bundle2.js looks like this:

'use strict';

function styleInject(css, ref) {
  // plugin function, removed for clarity
}

var css = "/*\n * Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.\n * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license\n */\n\n@import \"./_hidden.css\";\n@import \"./_reset.css\";\n@import \"./_zindex.css\";\n";
styleInject(css);

function mike () {
    console.log('Hello world');
}

module.exports = mike;

So rollup-plugin-postcss did not follow the nested @import statements here.

How to make this work?

1 Answer 1

12

Alright, the answer is that PostCSS itself needs plugins to handle @import statements. So the rollup config you need is:

import resolve from 'rollup-plugin-node-resolve';
import postcss from 'rollup-plugin-postcss'

import postcssImport from 'postcss-import';


export default {
    input: 'src/mike.js',
    output: {
        file: 'public/bundle2.js',
        format: 'cjs'
    },
    plugins: [resolve(),
        postcss({
            plugins: [postcssImport()]
        })]
};
Sign up to request clarification or add additional context in comments.

1 Comment

For what it's worth, resolve() was causing an issue for me. Taking it out still inlined imported css.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.