Comments (25)
Hm. PostCSS now save return result.map
only for non-inline maps. But we can change API :).
Why you need inline map and map content to save it to separated file?
from postcss.
Current API is:
- You pass input CSS and user options and didn’t think ever about maps.
- PostCSS autodetect previous map, check options.
- If PostCSS decide to write output map file, it will add
.map
property to result.
var result = postcss(processor).process(css, opts);
fs.writeFileSync('out.css', result.css);
if ( result.map) {
fs.writeFileSync('out.css.map', result.map);
}
from postcss.
You can ask PostCSS to process map to result.map
and inline it by yourself:
var result = postcss(processor).process(css, map: true, inlineMap: false);
var output = result.css;
var base64 = new Buffer(result.map).toString('base64');
output += "\n/*# sourceMappingURL= data:application/json;base64," + base64 + " */";
from postcss.
Thanks for getting back to me!
What I want is to only ever have 1 file. For asset pipelining it makes things a bit easier to manage. Sort of the same reason you inline the map. You could write 3 files, inlining the map cuts it down to 2, inlining the source too is a big win!
That last thing might be what I need to do.
Because PostCSS is building the inline portion itself, I would either need to depend on PostCSS to inline the source too, or I would need to pretend like I don't want inline CSS and then inline it myself. Maybe I'll just do that.
I'll give it a shot. I'll close this for now and let you know how it goes.
Thanks!
from postcss.
Let me know what I might be screwing up?
Input
:fullscreen a {
transition: transform 1s
}
body {
padding:100px;
}
Code
var opts = {
map: true,
inlineMap: false
};
var result = autoprefixer.process( file.outputFileText, opts );
Output
:-moz-full-screen a {
transition: transform 1s
}
:fullscreen a {
transition: transform 1s
}
body {
padding:100px;
}
/*# sourceMappingURL=to.css.map */
Is there anything specific I need to do to get it to not tack on that source map line at the bottom? Obviously I can remove the last line if that's the route I need to go.
from postcss.
You set map: true
to generate maps and inlineMap: false
to generate in-file map, instead of inline. So your map files now is in result.map
.
I didn’t understand what you really whant in this example.
If you want to remove /*# sourceMappingURL=to.css.map */
, add mapAnnotation: false
option.
If you want to inline map to CSS (but you willn’t have result.map
), set inlineMap: true
.
from postcss.
What I want is this
:-moz-full-screen a {
transition: transform 1s
}
:fullscreen a {
transition: transform 1s
}
body {
padding:100px;
}
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiL1VzZXJzL2RiYXNoZm9yZC9taW1vc2FwbGF5L2Zvby9wdWJsaWMvc3R5bGVzaGVldHMvZm9vLmNzcyIsInNvdXJjZXMiOlsiL1VzZXJzL2RiYXNoZm9yZC9taW1vc2FwbGF5L2Zvby9hc3NldHMvc3R5bGVzaGVldHMvZm9vLmNzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtJQUNJLHlCQUF3QjtFQUMzQjs7QUFGRDtJQUNJLHlCQUF3QjtFQUMzQjs7QUFFRDtFQUNFLGVBQWM7RUFDZiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyI6ZnVsbHNjcmVlbiBhIHtcbiAgICB0cmFuc2l0aW9uOiB0cmFuc2Zvcm0gMXNcbn1cblxuYm9keSB7XG4gIHBhZGRpbmc6MTAwcHg7XG59Il19 */
That has both the map and the source inlined together. I didn't know how to remove the mapAnnotation
. I hadn't noticed that in the docs, but I see it now. I'll give that a shot.
from postcss.
You want just inline map. You need only inlineMap: true
option without magic:
var result = autoprefixer.process( file.outputFileText, { inlineMap: true });
from postcss.
But that doesn't include the source it seems? It just inlines the map?
from postcss.
Oh, I finally understand you :). You didn’t like, what map will generated?
OK, why you need sourcesContent
?
from postcss.
Maybe it'll help if I decode the base64 and format the JSON
{
"version":3,
"file":"/Users/dbashford/mimosaplay/foo/public/stylesheets/foo.css",
"sources":[
"/Users/dbashford/mimosaplay/foo/assets/stylesheets/foo.css"
],
"names":[
],
"mappings":"AAAA;IACI,yBAAwB;EAC3B;;AAFD;IACI,yBAAwB;EAC3B;;AAED;EACE,eAAc;EACf",
"sourceRoot":"",
"sourcesContent":[
":fullscreen a {\n transition: transform 1s\n}\n\nbody {\n padding:100px;\n}"
]
}
Notice sourcesContent
?
from postcss.
Like I said above, 1 file is easier than 2. For the same reason you inline the map, so you don't have to write the .map
file, I don't want to have to write the .src
file. Ideally I just want one file that has it all. Less file IO the better, mostly just because its easier to manage.
That make sense?
You have provided the ability to get what I need, I just have to build it myself. This works:
var opts = {
map: true,
inlineMap: false,
mapAnnotation: false
};
var result = autoprefixer.process( text, opts );
var sourceMap = JSON.parse( result.map );
sourceMap.sourceRoot = "";
sourceMap.sources[0] = inputFileName;
sourceMap.sourcesContent = [text];
sourceMap.file = outputFileName;
var base64SourceMap = new Buffer( JSON.stringify( sourceMap ) ).toString( "base64" );
var datauri = "data:application/json;base64," + base64SourceMap;
outputFileText = result.css + "\n/*# sourceMappingURL=" + datauri + " */\n";
from postcss.
But how browsers will use sourcesContent
right know? They only show rule destenation according maps.
from postcss.
I think PostCSS should had mapSource
option. And also detect source in prevous map. But I will add this feature maybe only after few week :(.
In your case right now I recommend to build map yourself. Next version will support sources content and you can clean your code.
from postcss.
Sounds great!
Chrome supports this out of the box. Firefox just added CSS source maps and I don't believe it supports inline source.
I handled this with CoffeeScript maps by allowing devs to toggle a flag for whether they want everything broken out into separate files or if they want it all inlined with it defaulting to inline. I wasn't planning on doing this for the autoprefixer stuff unless someone asks for it.
The advantage to separate source files is it'll let you edit the source in the browser. Being able to edit the source in the browser is nice, but if you have live reload its practically the same thing. Just as instant as editing in the browser to be honest.
Appreciate all your help!
from postcss.
Definitely no hurry on this. Like I said, the mechanism to do it is there, just a little extra work. 8 lines of code isn't going to kill me. =)
from postcss.
@dbashford yeap, I understand that this mechanism is ugly, but on this week I willn’t have a time :(. But we definitely will clean your hack in next release by mapSource
option. Or maybe we should use sourceContent: true
option?
from postcss.
I think sourceContent
is a little better than mapSource
. It matches the inline property name. Anyone (like me) who needs to use it will understand what that flag does right away without reading the docs. =)
from postcss.
Done f7e61a5
It will be in 1.0 release in this or next week.
from postcss.
Option will be map: { sourcesContent: true }
from postcss.
Wouldn’t it be better if the option was called sourceContents
, since that’s the name of the property of source maps?
from postcss.
@lydell spec contains sourcesContent
from postcss.
Sorry, you’re right.
from postcss.
Thanks for pointing that out to me! Seems like I’ve been doing it wrong all the time in source-map-resolve. How embarrassing.
from postcss.
@lydell don’t worry, everyone happy with Referer
in HTTP :)
from postcss.
Related Issues (20)
- Postcss generates invalid css from tailwind @apply HOT 3
- warning while building my Next js application due to which not able to deploy on Vercel. HOT 1
- Get `Unexpected token 'export'` even the project type is already set to `module` HOT 1
- Getting vulnerability in Postcss. HOT 1
- A research for generating PR checklists in Pull Request Template HOT 1
- question/feature request(lint): “not modify” mode for linters HOT 1
- Vulnerability in Postcss despite update HOT 2
- "Unexpected }" error when using comments in interpolation strings HOT 3
- Why does `NoWorkResult` exist? HOT 6
- Is it correct that a `NoWorkResult` is returned when a sourcemap is requested? HOT 4
- Unkown word Error HOT 5
- Unclosed bracket error in url HOT 5
- [vite:css] [postcss] original.line and original.column are not numbers HOT 55
- PostCSS Line Return Parsing Error In Postcss HOT 1
- AtRule#nodes can be undefined HOT 2
- Typings change in `3.4.34` breaks our dev flow for almost all our plugins HOT 7
- [plugin:vite:css] [postcss] Cannot read properties of undefined (reading 'join') HOT 1
- PostCSS issues and Next.js HOT 5
- Unable to obtain Px in LengthUnit HOT 1
- SyntaxError: Invalid or unexpected token HOT 1
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 postcss.