๋๋ LESS๋ฅผ ์ฌ์ฉํ์ฌ ๋ด ์ ํ๋ฆฌ์ผ์ด์ ์์ ํ ๋ง๋ฅผ ๊ตฌํํ๊ณ nodejs๋ณด๋ค ์ ์ ๋ชจ๋์ ์ฌ์ฉํ์ฌ CSS์ ๋ ์ ์ ํ์ผ์ ์ปดํ์ผํ์ง๋ง ํน์ ์๋๋ฆฌ์ค์์๋ ์๋ํ์ง ์์ต๋๋ค.
๋ํ ๋ด ์์ฉ ํ๋ก๊ทธ๋จ์ Bootstrap์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ Bootstrap์ด ์ ์ ์์ค ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ด ์์ฉ ํ๋ก๊ทธ๋จ์์ ์ํ๋ CSS๋ง ์ปดํ์ผํ๊ณ ์์ต๋๋ค.
๋ค์ํ ํ ๋ง์์ ๋ถํธ์คํธ๋ฉ ๋ณ์์ ๋ฏน์ค์ธ์ ์ฌ์ ์ํ ์๋ ์์ต๋๋ค. ๋ฐ๋ผ์ Bootstrap์ ์ปดํ์ผํ๋ ๋์ ํน์ ํ ๋ง ๋ณ์์ ๋ฏน์ค์ธ๋ ๊ณ ๋ คํด์ผ ํฉ๋๋ค.
๋ฐ๋ผ์ ๋ถํธ์คํธ๋ฉ ๋ณ์/๋ฏน์ค์ธ๊ณผ CSS ๊ท์น์ ๊ตฌ๋ณํ์ฌ 2๊ฐ์ ๋ค๋ฅธ ํ์ผ์ ๋ง๋ค์์ต๋๋ค.
์ ํ๋ฆฌ์ผ์ด์ ์ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ
|--sample_application
|--resources
| |--libraries
| |--bootstrap
| |--css
| | |--application.less
| |--less
| | |--application_variables.less
|--themes
|--red
| |--mixins
| | |--mixins.less
| |--variables
| | |--variables.less
| |--red.less
|--blue
| |--mixins
| | |--mixins.less
| |--variables
| | |--variables.less
| |--blue.less
|--themes.less
์ด๋ค ํ์ผ์ด ๋ฌด์์ ํฌํจํ๋์ง์ ๋ํ ์ค๋ช ์ ๋ฌด์์ ๋๊น?
1. /sample_application/themes/<-theme_name->/mixins/mixins.less
์ด ํ์ผ์๋ ๋ชจ๋ ์์ฉ ํ๋ก๊ทธ๋จ๋ณ ๋ฏน์ค์ธ๊ณผ ์ฌ์ ์๋ ๋ถํธ์คํธ๋ฉ ๋ฏน์ค์ธ์ด ํฌํจ๋์ด ์์ต๋๋ค.
.my-hover-mixin(@color) {
&:hover {
border: 2px solid @color;
}
}
/*Other theme specific mixins*/
2. /sample_application/themes/<-theme_name->/variables/variables.less
์ด ํ์ผ์๋ ๋ชจ๋ ์์ฉ ํ๋ก๊ทธ๋จ๋ณ ๋ณ์์ ์ฌ์ ์๋ ๋ถํธ์คํธ๋ฉ ๋ณ์๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
@text-color:#333333;
@border-color:#999999;
@body-bg-color:red;
/*Other theme specific variables*/
3. /sample_application/themes/<-theme_name->/<-theme_name->.less
์ด ํ์ผ์๋ ํน์ ํ
๋ง์ ๋ํ ๋ฏน์ค์ธ ๋ฐ ๋ณ์์ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
<strong i="10">@import</strong> "./variables/variables.less";
<strong i="11">@import</strong> "./mixins/mixins.less";
4. /sample_application/themes/theme.less
์ด ํ์ผ์๋ ๋ ๊ฐ์ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ๋ application_variables.less์ธ ๋ถํธ์คํธ๋ฉ ๋ณ์์ ๋ํ ๊ฒ์ด๊ณ ๋ ๋ฒ์งธ๋ ํน์ ํ
๋ง์ ๊ธฐ๋ณธ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ํ ๊ฒ์
๋๋ค. red.less/blue.less
<strong i="17">@import</strong> "application_variables.less";
<strong i="18">@import</strong> "red/red.less";
5. /sample_application/resources/libraries/bootstrap/css/application.less
์ด ํ์ผ์๋ /themes/themes.less ๋ฐ ๋ชจ๋ ํ์ ๋ถํธ์คํธ๋ฉ CSS ๊ท์น์ธ ํ์ผ ๊ฐ์ ธ์ค๊ธฐ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
<strong i="24">@import</strong> "theme.less";
/*Bootstrap CSS rules*/
6. /sample_application/resources/libraries/bootstrap/less/application_variables.less
์ด ํ์ผ์๋ ํ์ํ ๋ชจ๋ ๋ถํธ์คํธ๋ฉ ๋ณ์์ ๋ฏน์ค์ธ์ด ํฌํจ๋์ด ์์ต๋๋ค.
/*Bootstrap variables and mixins*/
์ด์ compile-bootstrap.js์ธ ๋ถํธ ์คํธ๋ฉ์ ๋ ์ปดํ์ผํ๋ ํ๋์ ๋ ธ๋ ์คํฌ๋ฆฝํธ ํ์ผ์ด ์์ต๋๋ค.
var fs = require("fs");
var less = require('less');
(function() {
var bsLessContent = fs.readFileSync("sample_application/resources/libraries/bootstrap/css/application.less");
less.render(bsLessContent.toString(), {
paths : [ "sample_application/themes/", "sample_application/resources/libraries/bootstrap/less/"],
compress : true
}, function(e, output) {
fs.writeFileSync("sample_application/resources/libraries/bootstrap/css/application.css", output);
});
})();
๊ทธ๋ฌ๋์ด ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ ๋ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
{ [Error: 'application_variables.less' wasn't found]
type: 'File',
message: '\'application_variables.less\' wasn\'t found',
filename: 'sample_application\\themes\\theme.less',
index: 18,
line: 2,
callLine: NaN,
callExtract: undefined,
column: 0,
extract:
[ '<strong i="6">@import</strong> "application_variables.less";',
'<strong i="7">@import</strong> "red/red.less";' ] }
๊ทธ๋ฐ ๋ค์ ์๋ ๊ฒฝ๋ก๋ ์ฌ์ฉํด ๋ณด์์ง๋ง ์ฌ์ ํ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
{ [Error: './../resources/libraries/bootstrap/less/application_variables.less' wasn't found]
type: 'File',
message: '\'./../resources/libraries/bootstrap/less/application_variables.less\' wasn\'t found',
filename: 'sample_application\\themes\\theme.less',
index: 18,
line: 2,
callLine: NaN,
callExtract: undefined,
column: 0,
extract:
[ '<strong i="11">@import</strong> "./../resources/libraries/bootstrap/less/application_variables.less";',
'<strong i="12">@import</strong> "red/red.less";' ] }
์์ค๊ฐ ๋ฌธ์์ด๋ก ์ปดํ์ผ๋ฌ์ ์ ๊ณต๋๊ธฐ ๋๋ฌธ์ ์ปดํ์ผ๋ฌ๊ฐ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ํ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ก ์ฌ์ฉํ ์ ์๋๋ก ์๋ณธ ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ช
์์ ์ผ๋ก ์ค์ ํด์ผ ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ชจ๋ ๊ฒฝ๋ก๊ฐ ๋ฌด์์ธ์ง ์ ์ ์์ต๋๋ค. ์ง์ ์ ์๋์ ์
๋๋ค(๋๋ถ๋ถ cwd
๋ง ์ฌ์ฉํ์ง๋ง ์ค์ ๋ก ๊ฐ์ ธ์ค๊ธฐ์ ๊ด๋ จํ์ฌ ๊ฑฐ์ "์์"์ด๋ฉฐ ๋ ์ด์ ํ๋ก์ ํธ ๋ฃจํธ๋ฅผ ๊ฐ๋ฆฌํฌ ํ์๊ฐ ์์ต๋๋ค...). ์:
var fs = require('fs'),
path = require('path'),
less = require('less');
(function() {
var src = "foo/bar/baz.less";
less.render(fs.readFileSync(src).toString(), {
filename: path.resolve(src), // <- here we go
}, function(e, output) {
console.log(output.css);
});
})();
paths
์ต์
๋ ๋ง์ฐฌ๊ฐ์ง์
๋๋ค. ์ด ๊ฒฝ์ฐ์ ๋ด๊ฐ ํ๋ฆฌ์ง ์์ผ๋ฉด filename
๋ํด ์ ๋์ ์ด๊ฑฐ๋ ์๋์ ์ด์ด์ผ ํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก lessc
์์ฒด ๊ฐ ์ด๋ฌํ ๊ฒ๋ค์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ๋ ๊ฒ์ด ์ข์ต๋๋ค.
Seven-phases-max๋, ๊ฐ์ฌํฉ๋๋ค. ์ด ์๋ฃจ์ ์ ์ ๋๋ก ์๋ํ๋ฏ๋ก ๋ฌธ์ ๋ฅผ ์ข ๋ฃํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์์ค๊ฐ ๋ฌธ์์ด๋ก ์ปดํ์ผ๋ฌ์ ์ ๊ณต๋๊ธฐ ๋๋ฌธ์ ์ปดํ์ผ๋ฌ๊ฐ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ํ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ก ์ฌ์ฉํ ์ ์๋๋ก ์๋ณธ ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ช ์์ ์ผ๋ก ์ค์ ํด์ผ ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ชจ๋ ๊ฒฝ๋ก๊ฐ ๋ฌด์์ธ์ง ์ ์ ์์ต๋๋ค. ์ง์ ์ ์๋์ ์ ๋๋ค(๋๋ถ๋ถ
cwd
๋ง ์ฌ์ฉํ์ง๋ง ์ค์ ๋ก ๊ฐ์ ธ์ค๊ธฐ์ ๊ด๋ จํ์ฌ ๊ฑฐ์ "์์"์ด๋ฉฐ ๋ ์ด์ ํ๋ก์ ํธ ๋ฃจํธ๋ฅผ ๊ฐ๋ฆฌํฌ ํ์๊ฐ ์์ต๋๋ค...). ์:paths
์ต์ ๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค. ์ด ๊ฒฝ์ฐ์ ๋ด๊ฐ ํ๋ฆฌ์ง ์์ผ๋ฉดfilename
๋ํด ์ ๋์ ์ด๊ฑฐ๋ ์๋์ ์ด์ด์ผ ํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋กlessc
์์ฒด ๊ฐ ์ด๋ฌํ ๊ฒ๋ค์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ๋ ๊ฒ์ด ์ข์ต๋๋ค.