Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

How can you split a css file into multiple using just postcss #6

Open
matthewrobb opened this issue Jan 2, 2016 · 1 comment
Open

Comments

@matthewrobb
Copy link

I can't seem to find anything in the code and I honestly haven't tested if it's working but I am very curious. It seems as thought postcss assumes a 1:1 for from-file:to-file and I can't seem to find a way using only postcss to do 1:n+1 specially not in a way that would work in, for example, gulp-postcss

@nsams
Copy link
Contributor

nsams commented Jan 2, 2016

Usage example:

var postcss = require('postcss');
var postcssChunk = require('postcss-chunk');

var instance = postcss([
    postcssChunk({ size: 4000 })
]);
var css = '';
process.stdin.setEncoding('utf-8')
process.stdin.on('data', function(buf) { css += buf.toString(); });
process.stdin.on('end', function() {
    instance.process(css).then(function (result) {
        var first = true;
        result.chunks.forEach(function(chunk) {
            if (!first) {
                process.stdout.write("\n/* ***** NEXT CHUNK ***** */\n");
            }
            process.stdout.write(chunk.css);
            first = false;
        });
    }).catch(function(e) {
        console.log(e);
        process.exit(1);
    });
});
process.stdin.resume();

this should be added in readme...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants