Created
January 30, 2018 06:13
-
-
Save leaysgur/154d5bbb4a0191299aac48345b0f09aa to your computer and use it in GitHub Desktop.
Enable multiple entries with postcss-cli.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const { spawn } = require('child_process'); | |
const flags = process.argv.slice(2); | |
const config = require('./postcss.config.js'); | |
// Parse postcss.config.js's extra fileds like webpack.config.js | |
const entries = []; | |
for (const [name, src] of Object.entries(config.entry)) { | |
const input = path.join(config.context, src); | |
const output = path.join(config.output.path, config.output.filename).replace('[name]', name); | |
entries.push({ name, input, output }); | |
} | |
// Convert config into commands to exec | |
const cmds = []; | |
for (const entry of entries) { | |
const cmd = { | |
cmd: './node_modules/.bin/postcss', | |
args: [ | |
entry.input, | |
'-o', | |
entry.output, | |
] | |
}; | |
if (flags.includes('-w') || flags.includes('--watch')) { | |
cmd.args.push('-w'); | |
} | |
cmds.push(cmd); | |
} | |
// Spawn commands | |
for (const { cmd, args } of cmds) { | |
const proc = spawn(cmd, args); | |
// don't know why but all message goes stderr | |
proc.stderr.on('data', data => { | |
console.log(data.toString()); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const rootPath = path.resolve(''); | |
module.exports = { | |
context: rootPath, | |
entry: { | |
index: './src/index/main.css', | |
room: './src/room/main.css', | |
}, | |
output: { | |
path: `${rootPath}/public`, | |
filename: '[name].bundle.css', | |
}, | |
plugins: { | |
'postcss-import': {}, | |
'postcss-nested': {}, | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment