Skip to content

Instantly share code, notes, and snippets.

@codrin-iftimie
Last active April 18, 2016 07:36
Show Gist options
  • Save codrin-iftimie/65e8c37e8dbea7f9af5a09549156825d to your computer and use it in GitHub Desktop.
Save codrin-iftimie/65e8c37e8dbea7f9af5a09549156825d to your computer and use it in GitHub Desktop.
import csjs from "csjs";
const pink = "#c74d5a";
const white = "#fff";
export default csjs`
.simple-button {
background-color: ${pink};
border-radius: 3px;
color: ${white};
}
`;
//create this file under node_modules/csjs
var getCss = require("csjs/get-css");
var csjs = require("csjs");
var requireFromString = require("require-from-string");
module.exports = function(source) {
var parsedSource = requireFromString(source);
return getCss(parsedSource.__esModule ? parsedSource.default : parsedSource);
}
import csjs from "csjs";
const white = "#fff";
const pink = "#c74d5a";
import button from "./button.csjs"; // since webpack interprets this it will transform it into string.
// the import is undefined
export default csjs`
.shallow-button extends ${button['simple-button']} { // tries to extend undefined['simple-button']
background-color: ${white};
border: 1px solid #ddd;
}
.shallow-button:hover {
background-color: ${pink};
border-color: ${pink};
color: ${white};
}
`;
var path = require("path");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: "./index.js",
output: {
path: path.resolve(__dirname, "assets"),
publicPath: "/assets/",
filename: "index.js",
},
plugins: [
new ExtractTextPlugin("styles.css")
],
module: {
loaders: [
{
test: /\.js?$/,
loader: "babel-loader",
exclude: /node_modules/,
query: {
cacheDirectory: true
}
}, {
test: /\.csjs.js?$/,
loader: ExtractTextPlugin.extract("css-loader!csjs-loader!babel-loader")
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment