Comments (12)
Can you please provide whole .babelrc
configuration file?
Ad 2) I am afraid that I can't resolve your problem with postcss-import
because this plugin uses css-modules-require-hook
under the hood, so if it is incompatible with it I can't do anything.
from babel-plugin-css-modules-transform.
My .babelrc:
module.exports = {
only: /\.jsx$/,
plugins: [
'babel-plugin-syntax-async-generators',
'babel-plugin-syntax-trailing-function-commas',
'babel-plugin-transform-async-to-module-method',
'babel-plugin-transform-class-properties',
'babel-plugin-transform-decorators-legacy',
'babel-plugin-transform-runtime',
'babel-plugin-transform-es2015-destructuring',
'babel-plugin-transform-es2015-function-name',
'babel-plugin-transform-es2015-modules-commonjs',
'babel-plugin-transform-es2015-parameters',
'babel-plugin-transform-es2015-sticky-regex',
'babel-plugin-transform-es2015-unicode-regex',
'babel-plugin-transform-eval',
'babel-plugin-transform-object-assign',
'babel-plugin-transform-object-rest-spread',
'babel-plugin-transform-proto-to-assign',
'babel-plugin-transform-react-display-name',
'babel-plugin-transform-react-jsx',
'babel-plugin-transform-undefined-to-void',
['babel-plugin-transform-async-to-module-method', {
'module': 'bluebird',
'method': 'coroutine',
}],
'babel-plugin-transform-react-jsx',
['babel-plugin-css-modules-transform', {
'prepend': ['postcss-cssnext'],
}],
],
sourceMaps: 'both',
retainLines: true,
};
from babel-plugin-css-modules-transform.
Thank you. One more question, you mentioned that you want to pass specific options to postcss-cssnext
. Can you please provide an example of configuration file? How it should look?
from babel-plugin-css-modules-transform.
With postcss-cssnext
, i can provide custom-properties
& custom-media
like :
// postcssConfig.js
import postcssCssnext from 'postcss-cssnext';
import constants from './lib/css/constants';
const { properties, media } = constants;
export default {
postcssCssnext: postcssCssnext({
features: {
customProperties: {
variables: properties,
},
customMedia: {
extensions: media,
},
},
}),
};
And i use this file with webpack (in order to build my front bundle):
// webpackConfig.js
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import postcssConfig from './postcssConfig';
const { postcssCssnext } = postcssConfig;
export default {
...
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader'),
}
],
},
postcss: () => [postcssCssnext],
plugins: [
new ExtractTextPlugin(path.resolve(__dirname, '/path/to/bundle/c.css'), {
allChunks: true,
}),
],
}
from babel-plugin-css-modules-transform.
You can do it already. Only thing you need to do is to create javascript file, where you import postcss-cssnext
plugin and export function that will configure this plugin.
You can try this:
// postcss.js
import postcssCssnext from 'postcss-cssnext';
import constants from './lib/css/constants';
const { properties, media } = constants;
export default () => postcssCssnext({
features: {
customProperties: {
variables: properties,
},
customMedia: {
extensions: media,
},
},
});
and then set prepend
to something like "prepend": ["./postcss.js"]
I am writing this on the fly, so it's not tested.
from babel-plugin-css-modules-transform.
Hmmm, when css-modules-transform
try to resolve the prepend path here:
https://github.com/michalkvasnicak/babel-plugin-css-modules-transform/blob/master/src/index.js#L107
It fails with plugin = './postcss.js'
.
Then it try a second time here:
https://github.com/michalkvasnicak/babel-plugin-css-modules-transform/blob/master/src/index.js#L110
But it fails again.
I think its because of path
value: its a NodePath
, not a regular path like: /foo/bar/qux.js
from babel-plugin-css-modules-transform.
Is this path to a plugin relative to the process.cwd()
? Does result of resolve
exist on your filesystem?
from babel-plugin-css-modules-transform.
process.cwd()
refers to my working directory:
/foo/bar/www
my JS file postcss.js
is located here: /foo/bar/www/postcss.js
.
and i run my gulp task at /foo/bar/www
.
But value of path
is weird, it's not a string
, it's a Object[NodePath]
.
from babel-plugin-css-modules-transform.
Try to change it to plugin
on line 110
. I think you found a bug :)
path
=> plugin
from babel-plugin-css-modules-transform.
It works π with the update at L110
.
It's nice!
It remains for me to investigate the css-module-require-hook
about async plugin error ;).
from babel-plugin-css-modules-transform.
Ok now you can update it, released as 0.0.9
:) Thank you
from babel-plugin-css-modules-transform.
I'd just like to add a comment that I solved the issue of not passing options by doing this in my webpack babel loader:
var theme = require('postcss-theme');
...
var themePath = path.resolve(baseThemePath, config.theme).split(path.sep).join('/');
theme.bind(this, {themePath: themePath}),
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
plugins: [
[
"css-modules-transform", {
"generateScopedName": "[name]__[local]__[hash:base64:5]",
"prepend": [
theme.bind(this, {themePath: themePath}),
traits.bind(this, {traitsPath: baseTraitsPath})
],
"append": [
// plugin to add :focus selector to every :hover for keyboard accessibility.
postcssFocus,
// PostCSS-cssnext is a PostCSS plugin that allows us to use the latest CSS syntax.
// It transforms CSS specs into more compatible CSS so you donβt need to wait for browser support.
// Including Chrome 44 as it has a high percentage as at 1/2/17 due to Internet app on Samsung phones
// format: https://github.com/ai/browserslist
cssnext.bind(this, {
browsers: ['last 2 versions', 'IE > 10', 'Chrome 44']
}),
postcssReporter.bind(this, {clearMessages: true})
]
}
]
]
}
}
from babel-plugin-css-modules-transform.
Related Issues (20)
- Relative urls are not resolved in extracted css
- dont work for css-loader@^2 HOT 3
- preprocessor errors and missing files are swallowed
- Rebuild extracted CSS file on original css file change (using parceljs instead of webpack)
- using babel-plugin-css-modules-transform with ssr not working HOT 2
- minimist vulnerability in 1.6.2 HOT 1
- Problems on Windows machines HOT 2
- Doesn't work with @babel/register, works only with @babel/cli
- It is not wroking with aliasing css HOT 1
- Better alternative
- Some local test cases fail
- "in" operator fails upon use of "resolve" option
- transform with less HOT 1
- implicitly registeres node hook HOT 1
- import without assign are not processed
- import named className doesn't work HOT 3
- Empty styles HOT 4
- Unable to require/import images when using this plugin
- babel-plugin-css-modules-transform and css-loader create different class names HOT 3
- Using Node's require to resolve file path does not resolve correct library from node_modules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-css-modules-transform.