3

I have a bunch of different css files being generated in css/ folder with help of libsass. Also I do have normalize.css already placed in css/ folder to allow normalization of css in all browsers. I'm using npm as build tool, and my package.json consists something like this:

{
.....
"scripts": {
    "test": "npm run lint",
    "lint": "csslint css/*.css",
    "build": "node-sass sass/ -o css/",
    "postbuild": "cat css/*.css | cleancss -o css/main.min.css"
  },
.....
}


At the build step I'm generating css files and in post-build step I'm concatenating all css files into one minified css file.

But during post-build step, the content of normalize.css file should come before any other css file content, however the behavior is inconsistent. I need to make sure that normalize stuff comes ahead of all other css files, any heads up would be helpful.


Tldr- Concatenation of bunch of css files results in normalize.css being appended in middle or last. I need it at start of concatenated css file.

Thanks.

Abhinav Gauniyal
  • 7,034
  • 7
  • 50
  • 93

1 Answers1

6

Simply use the -I option of ls to exclude normalize.css from being listed:

cd css/ && cat normalize.css `ls -I normalize.css -I main.min.css` | cleancss -o main.min.css
Community
  • 1
  • 1
Jerska
  • 11,722
  • 4
  • 35
  • 54
  • 2
    does `cat` shows files in alphabetical order of their filenames? – Abhinav Gauniyal Jul 04 '15 at 13:35
  • 2
    @AbhinavGauniyal No, `cat` uses the order of its arguments, so here, `normalize.css` first, and then the order from `ls`, which by default is in alphabetical order. (See http://stackoverflow.com/questions/878249/unixs-ls-sort-by-name ). If however you notice it isn't the case, just use `ls -I normalize.css *.css | sort` – Jerska Jul 04 '15 at 13:39
  • 2
    okay... `ls -I normalize.css *.css` even in terminal gives all css files including `normalize.css`, therefore defeating whole purpose. Can you look into it please. – Abhinav Gauniyal Jul 04 '15 at 13:53
  • 1
    You're right, it seems to only work when calling ls on a folder. You should only have css files in your `css/` directory, so I believe the edit I just made should work. (By the way, until now, you were reconcatenating `main.min.css` into itself) – Jerska Jul 04 '15 at 13:57
  • 1
    Using `-I normalize.css *css` doesn't make sense, because you're saying "Ignore normalize.css but show me normalize.css" as part of the `*` expansion. if you want use `-I` you should not use the `*` expansion as well – Eric Renouf Jul 04 '15 at 13:59
  • 2
    @EricRenouf Yes, I've realized that with OP's comment, hence the edit. – Jerska Jul 04 '15 at 14:00
  • I'm a moron in this stuff. Thankyou again for resolving this quickly :) – Abhinav Gauniyal Jul 04 '15 at 14:00