Last active
September 13, 2015 02:24
-
-
Save wwayne/c11224dd173a2cf606d3 to your computer and use it in GitHub Desktop.
Insert sass into react component which will be shared from npm
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
var sass = require('node-sass') | |
var fs = require('fs') | |
var path = require('path') | |
function transferSass () { | |
sass.render({ | |
file: path.resolve(__dirname, '../src/index.scss'), //source scss file | |
outputStyle: 'compressed' | |
}, function (err, result) { | |
if (err) { | |
console.log(err) | |
return | |
} | |
// style.js will exports a string which filled with css transformed from sass | |
fs.writeFile(path.resolve(__dirname, '../src/style.js'), "export default '" + result.css.toString().replace(/\n/g, '') + "'", function (err) { | |
if (err) { | |
console.error(err) | |
} | |
console.log('css file has been transformed success') | |
}) | |
}) | |
} | |
transferSass() | |
// watch the scss file's change | |
fs.watch(path.resolve(__dirname, '../src/index.scss'), function (event, filename) { | |
console.log(event, filename) | |
transferSass() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment