diff --git a/src/style/index.js b/src/style/index.js index 74473b0..10da810 100644 --- a/src/style/index.js +++ b/src/style/index.js @@ -2,7 +2,7 @@ import { writeFile, mkdirSync as mkdir, existsSync as exists } from 'fs' import { dirname, isAbsolute, resolve as resolvePath } from 'path' import compileCSS from './css' import compileSCSS from './scss' -import compileLESS from './less' +import compileLESS from './less/index' import compileSTYLUS from './stylus' const compilers = { diff --git a/src/style/less.js b/src/style/less.js deleted file mode 100644 index edb4074..0000000 --- a/src/style/less.js +++ /dev/null @@ -1,20 +0,0 @@ -export default async function (style, options) { - const less = require('less') - const { css, map } = await less.render( - 'data' in options.less ? `${options.less.data}\n${style.code}` : style.code, - { - sourceMap: { - sourceMapFullFilename: style.id, - sourceMapFileInline: false - }, - ...options.less - } - ) - - style.$compiled = { - code: css.toString(), - map: map.toString() - } - - return style -} diff --git a/src/style/less/index.js b/src/style/less/index.js new file mode 100644 index 0000000..41054a9 --- /dev/null +++ b/src/style/less/index.js @@ -0,0 +1,27 @@ +import path from 'path' + +export default async function (style, options) { + const less = require('less') + const config = { + plugins: [], + paths: [], + sourceMap: { + sourceMapFullFilename: style.id, + sourceMapFileInline: false + }, + ...options.less + } + + config.paths.unshift(path.dirname(style.id)) + + const { css, map } = await less.render( + 'data' in options.less ? `${options.less.data}\n${style.code}` : style.code, config + ) + + style.$compiled = { + code: css.toString(), + map: map.toString() + } + + return style +} diff --git a/test/expects/import-less.css b/test/expects/import-less.css new file mode 100644 index 0000000..e7c946d --- /dev/null +++ b/test/expects/import-less.css @@ -0,0 +1,3 @@ +.hello { + color: red; +} \ No newline at end of file diff --git a/test/expects/import-less.js b/test/expects/import-less.js new file mode 100644 index 0000000..32ac936 --- /dev/null +++ b/test/expects/import-less.js @@ -0,0 +1,3 @@ +var importLess = { template: "
",}; + +export default importLess; \ No newline at end of file diff --git a/test/expects/import-scss.css b/test/expects/import-scss.css new file mode 100644 index 0000000..81a6d50 --- /dev/null +++ b/test/expects/import-scss.css @@ -0,0 +1,2 @@ +.hello { + color: red; } \ No newline at end of file diff --git a/test/expects/import-scss.js b/test/expects/import-scss.js new file mode 100644 index 0000000..daffe4e --- /dev/null +++ b/test/expects/import-scss.js @@ -0,0 +1,3 @@ +var importScss = { template: "
",}; + +export default importScss; \ No newline at end of file diff --git a/test/fixtures/import-less.vue b/test/fixtures/import-less.vue new file mode 100644 index 0000000..6c9a0ce --- /dev/null +++ b/test/fixtures/import-less.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/test/fixtures/import-scss.vue b/test/fixtures/import-scss.vue new file mode 100644 index 0000000..6c49f89 --- /dev/null +++ b/test/fixtures/import-scss.vue @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/test/fixtures/some.less b/test/fixtures/some.less new file mode 100644 index 0000000..4970069 --- /dev/null +++ b/test/fixtures/some.less @@ -0,0 +1,5 @@ +@var: red; + +.hello { + color: @var; +} diff --git a/test/fixtures/some.scss b/test/fixtures/some.scss new file mode 100644 index 0000000..33eb96f --- /dev/null +++ b/test/fixtures/some.scss @@ -0,0 +1,5 @@ +$var: red; + +.hello { + color: $var; +} diff --git a/test/test.js b/test/test.js index 7631ede..7ae3c27 100644 --- a/test/test.js +++ b/test/test.js @@ -49,14 +49,16 @@ function test(name) { // Check css output if ([ - 'style', 'css-modules', 'css-modules-static', + 'import-scss', + 'import-less', + 'less', + 'pug', 'scoped-css', 'scoped-css-with-no-auto-style', 'scss', - 'pug', - 'less', + 'style', 'stylus' ].indexOf(name) > -1) { var css = read('expects/' + name + '.css')