嵌套@import CSS语句未使用rollup-plugin-postcss汇总

时间:2019-12-12 08:34:37

标签: postcss rollupjs

我的源文件为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看起来像这样:

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

我有这个汇总配置:

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: []
    })]
};

汇总的public/bundle2.js如下所示:

'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;

因此,rollup-plugin-postcss在此处未遵循嵌套的@import语句。

如何进行这项工作?

1 个答案:

答案 0 :(得分:0)

好的,答案是PostCSS本身需要插件来处理@import语句。因此,您需要的汇总配置是:

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()]
        })]
};