Last active
December 11, 2018 08:49
-
-
Save amoshydra/f0a79123fd184088e7e674333d0fc191 to your computer and use it in GitHub Desktop.
My hack to temporary resolve this issue https://github.com/webpack-contrib/mini-css-extract-plugin/issues/113
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 fs = require('fs'); | |
const glob = require('glob'); | |
module.exports = (options = {}) => { | |
const collector = {}; | |
const stuffs = glob.sync(options.inputGlob) | |
.map(filepath => fs.readFileSync(filepath, { encoding: 'utf8' })) | |
.join('\n') | |
// Collect then remove import syntax | |
.replace(/@import url\([^;]+\);/g, (match) => { | |
collector[match] = true; | |
return ''; | |
}) | |
; | |
// Concatenate import syntax at the top of the file | |
const output = Object.keys(collector).join('\n') + stuffs; | |
fs.writeFileSync(options.output, output, { encoding: 'utf8' }); | |
}; | |
// Quick hack: If this file is being run directly as a node script, then execute the function immediately | |
if (__filename.includes(process.argv[1])) { | |
module.exports({ | |
inputGlob: process.argv[2], | |
output: process.argv[3], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment