-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
csjs-loader : webpack loader support #29
Comments
I've tried making such a loader. I even made it work with extract-text-webpack-plugin. Mostly the code you need is // csjs-loader.js
var requireFromString = require('require-from-string');
var getCss = require('csjs').getCss;
module.exports = function(source) {
return getCss(requireFromString(source));
} The problem is that you'd be interpreting all //simple_button.csjs.js
export default csjs`
.simple-button {
// styles ...
}
`;
//custom_button.csjs.js
import s from './simple_button.csjs' // <-- this is actually translated into css
export default csjs `
.primary-button extends `${s['simple-button']}` { // <-- you cannot extend it
// style
}
`; @rtsao Does this work well with csjs-extractify? |
@codrin-iftimie why does this disable the compose feature? And can you provide the code you used for webpack for extract-text? Would like to take a look. |
I've created a gist. |
I'm doing it using a little different approach. To be compatible with css modules, I'm setting styles.csjs.js module.exports = csjs`.myClass { ... }` app.js import { myClass } from './styles.csjs';
import { classFromCss } from './someCss.css'; webpack.config.js loaders: [
{
test: /\.csjs\.js?$/,
loader: 'style!csjs!val!babel',
}, {
test: /\.css$/,
loader: 'style!csjs!css!postcss',
},
],
const csjs = require('csjs');
const csjsify = (source) => (
typeof source === 'string'
? csjs`${source}`
: source
);
const stringify = (styles) => {
const result = Object.assign(styles, {});
Object.keys(result).forEach((k) => (result[k] = result[k].className));
return JSON.stringify(result);
};
module.exports = (source, map) => {
const styles = csjsify(source);
return `
module.exports = [[module.id, \`${csjs.getCss(styles)}\`, ${map}]];
module.exports.locals = ${stringify(styles)};
`;
}; I still didn't figure out how to enable sourcemaps using this approach. |
interesting, yes more thought is needed @mkazlauskas |
@SilentCicero I updated my previous comment, added support to pipe plain css files over csjs loader. This way we can keep external classes of dependencies scoped. |
That's sounds so amazingly great that we definitely should support source maps generation for |
I've been studying the csjs-extractify, but I don't know how I could approach it with the webpack loader model.
Thoughts? @rtsao
The text was updated successfully, but these errors were encountered: