@jrburke은 : 코드에 내가 조립 한 빠른 requirejs을 기반으로 플러그인이 :
define({
version: '0.1',
load: function(name, req, onLoad, config) {
req(['text!' + name, 'base/less'], function(lessText) {
var styleElem;
(new less.Parser()).parse(lessText, function (err, css) {
if (err) {
if (typeof console !== 'undefined' && console.error) {
console.error(err);
}
} else {
styleElem = document.createElement('style');
styleElem.type = 'text/css';
if (styleElem.styleSheet)
styleElem.styleSheet.cssText = css.toCSS();
else
styleElem.appendChild(document.createTextNode(css.toCSS()));
document.getElementsByTagName("head")[0].appendChild(styleElem);
}
onLoad(styleElem);
});
});
}
});
"기본/이하"포인트를 덜 소스. 당신은 또한 이것을 미리로드 할 수 있으며, 글로벌 less
오브젝트가 있다고 가정합니다. 이상적으로, 나는 더 적은 Parser 객체를이 플러그인 자체로 가져 와서 전역을 전혀 만들지 않기를 바란다.
처럼 물건을 할 수있는이 사용 :
require(['less!global.less'], function(elem) {
});
하는 시점에서, global.less 구문 분석되었으며 페이지에 추가 내가 제거하거나해야 할 경우 스타일 요소를 가리키는 ELEM를 다시 제공 어떤 이유로 그것을 수정하십시오.
아무에게도 의견이 있거나 더 좋은 방법을 알고 있습니까? @nicholas는 수입과 플러그인으로
건배
lessText에 @imports가있는 경우 어떻게 작동합니까? 우리는 여러 개의 파일을 requirejs 텍스트 모듈에 매핑하려고합니다 ... 가능합니까? 아무도 그것을 시험해 보지 않았습니까? – Rafael
안녕하세요 @jrburke, 귀하의 회신에 감사드립니다 requirejs 덜 스타일을 처리하기 위해 littele 라이브러리를 만들었습니다 https://github.com/pingsrl/requirejs-less – wezzy