Comments (7)
Amazing, thanks for this - have commited the change.
Yes, any help on the saveFile function would be greatly appreciated. It should be standard Java, I just wasn't sure about it and don't have a testing environment set up myself.
If you have any ideas for compression support in Rhino, let me know. Basically I'm calling this library currently - https://github.com/css/csso. Not sure how to call that within Rhino.
from require-css.
To clarify, the only thing needed to get the separateCSS output to work in Rhino, is to finish writing the 'saveFile' function. I've commented the place where it needs work (with a cry for help :P).
from require-css.
and here is the saveFile function :
function saveFile(path, data) {
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
var fs = require.nodeRequire('fs');
fs.writeFileSync(path, data, 'utf8');
}
else {
var encoding = "utf-8",
content = new java.lang.String(data),
output = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new java.io.FileOutputStream(path), encoding));
try {
output.write(0xffef);
output.write(content,0,content.length());
output.flush();
}
finally {
output.close();
}
}
}
A bit strange to write java mixed in javascript but that works for me and should be the java equivalent of the writeFileSync of node.js :)
I didn't touch the node.js part of the method ;)
For CSSO it would be a lot trickier because it seems it rely a lot on node.js module management and honestly I don't think it's worth it for the moment as the basic CSS compression is enough for me.
Just check it still works fine with node because I don't have one on my side.
You could probably regroup the "utf-8" string to be common for both java and node or even make it a configuration option since it's used at several places in the code but I let you do that! :p
from require-css.
Amazing, thanks so much for this!!
I ran the tests my side and everything seems to still be working fine so have committed that in.
Yes csso will be a little more tricky as you say - but the basic optimization should be enough.
One question - in the loadFile, there is a check against 0xfeff, while in the writeFile there is a write of 0xffef. Are these supposed to be different values?
from require-css.
I just kept that from your code, to be honnest I had no idea what they are there for :p
So now I checked : http://en.wikipedia.org/wiki/Byte_order_mark
And it should be FEFF.
It seems java doesn't use it and it's optional so you can just delete that line in the writeFile function.
But you need to let it in the load because if it's present java won't skip it, so you have to do it manually.
And yeah you can curse java for it's "great" file API... they redid it in java7 but most companies are still in older versions so I made my code as compliant as possible ;)
from require-css.
Ok I've taken it out of the write function. Makes sense if it's optional. Your code looks a lot simpler than the load function I must say though.
from require-css.
It's easier to write because you know the size of what you will write.
When you read you have to read each line until you are done and append it to the rest of the file. The added complexity is there that's all.
Then you have the BOM problem and the fact that they preserve the lines and the java factor which make it 10 lines bigger just because it's java (I love this language but for this kind of things it's really a pain when you don't have external libs)
from require-css.
Related Issues (20)
- explanation requested
- In IE8-9 onload does not fire in the second iframe HOT 1
- [Help!]There is a problem that load the css in iframe
- Is it possible to set media type when I load css via require?
- Require CSS in the path HOT 4
- Not working relative path's with baseUrl HOT 2
- How to skip css! references in r.js builds? HOT 1
- Removing CSS files (by reading the `removeCombined` property) HOT 3
- R.js build fails with external resources defined in the "paths" config property HOT 8
- req.toUrl is undefined HOT 2
- IE9: ieCurCallback null, Object expected HOT 1
- Error load timeout for css modules HOT 2
- In css-builder.js path.dirname(config.out) got an error HOT 2
- having trouble specifying path of css to load HOT 1
- R.js - Path must be a string HOT 4
- "Script-inlined CSS Benefits" - additional info
- how to work with commonjs module HOT 1
- When loading a cdn style sheet fails,How to load a local style sheet
- require-css load css file folder name conflict with plugin name
- Loading a css file that doesn't end with ".css"
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 require-css.