diff --git a/docs/introduction.md b/docs/introduction.md
index e7aa291..14b7164 100644
--- a/docs/introduction.md
+++ b/docs/introduction.md
@@ -1,4 +1,4 @@
-
+
diff --git a/package.json b/package.json
index e19b8b9..b199fc2 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,8 @@
"rollup-pluginutils": "^2.0.1",
"vue-template-compiler": "^2.1.10",
"vue-template-es2015-compiler": "^1.5.0",
- "vue-template-validator": "^1.1.5"
+ "vue-template-validator": "^1.1.5",
+ "less": "latest"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
diff --git a/src/style/index.js b/src/style/index.js
index 6193d66..cd61f11 100644
--- a/src/style/index.js
+++ b/src/style/index.js
@@ -1,10 +1,12 @@
import { writeFile } from 'fs'
import compileCSS from './css'
import compileSCSS from './scss'
+import compileLESS from './less'
const compilers = {
scss: compileSCSS,
- sass: compileSCSS
+ sass: compileSCSS,
+ less: compileLESS
}
export async function compile (style, options) {
@@ -30,7 +32,8 @@ export default function (files, options) {
Object.keys(files).forEach((file) => {
files[file].forEach((style) => {
- css += style.code + '\n'
+ css += ('$compiled' in style) ? `${style.$compiled.code}\n` : `${style.code}\n`
+
allStyles.push(style)
})
})
diff --git a/src/style/less.js b/src/style/less.js
new file mode 100644
index 0000000..bf197c8
--- /dev/null
+++ b/src/style/less.js
@@ -0,0 +1,18 @@
+import less from 'less'
+
+export default async function (style, options) {
+ const { css, map } = await less.render(style.code, {
+ sourceMap: {
+ sourceMapFullFilename: style.id,
+ sourceMapFileInline: false
+ },
+ ...options.less
+ })
+
+ style.$compiled = {
+ code: css.toString(),
+ map: map.toString()
+ }
+
+ return style
+}
diff --git a/src/vueTransform.js b/src/vueTransform.js
index 973d241..298bda2 100644
--- a/src/vueTransform.js
+++ b/src/vueTransform.js
@@ -109,7 +109,7 @@ function injectTemplate (script, template, lang, options, modules) {
throw new Error('[rollup-plugin-vue] could not find place to inject template in script.')
}
-var validateTemplate = function (code, content, id) {
+function validateTemplate (code, content, id) {
const warnings = templateValidator(code, content)
if (warnings) {
const relativePath = relative(process.cwd(), id)
diff --git a/test/expects/css-modules-static.css b/test/expects/css-modules-static.css
index bee9afa..1abd677 100644
--- a/test/expects/css-modules-static.css
+++ b/test/expects/css-modules-static.css
@@ -1,3 +1,3 @@
-.test {
+.css-modules-static__test {
color: red;
}
\ No newline at end of file
diff --git a/test/expects/css-modules.css b/test/expects/css-modules.css
index bee9afa..9e35874 100644
--- a/test/expects/css-modules.css
+++ b/test/expects/css-modules.css
@@ -1,3 +1,3 @@
-.test {
+.css-modules__test {
color: red;
}
\ No newline at end of file
diff --git a/test/expects/less.css b/test/expects/less.css
new file mode 100644
index 0000000..92cfb71
--- /dev/null
+++ b/test/expects/less.css
@@ -0,0 +1,3 @@
+.less__test {
+ color: red;
+}
\ No newline at end of file
diff --git a/test/expects/less.js b/test/expects/less.js
new file mode 100644
index 0000000..ec5c631
--- /dev/null
+++ b/test/expects/less.js
@@ -0,0 +1,3 @@
+var less = { template: "
",cssModules: {"test":"less__test"},};
+
+export default less;
\ No newline at end of file
diff --git a/test/fixtures/less.vue b/test/fixtures/less.vue
new file mode 100644
index 0000000..fd3447d
--- /dev/null
+++ b/test/fixtures/less.vue
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
diff --git a/test/test.js b/test/test.js
index 992ad9e..a0f0e15 100644
--- a/test/test.js
+++ b/test/test.js
@@ -41,7 +41,7 @@ function test(name) {
assert.equal(code.trim(), expected.trim(), 'should compile code correctly')
// Check css output
- if (['style', 'css-modules', 'css-modules-static', 'scss', 'pug'].indexOf(name) > -1) {
+ if (['style', 'css-modules', 'css-modules-static', 'scss', 'pug', 'less'].indexOf(name) > -1) {
var css = read('expects/' + name + '.css')
assert.equal(css.trim(), actualCss.trim(), 'should output style tag content')
} else {
diff --git a/yarn.lock b/yarn.lock
index 81c3428..1b76861 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2689,7 +2689,7 @@ lcov-parse@0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/lcov-parse/-/lcov-parse-0.0.10.tgz#1b0b8ff9ac9c7889250582b70b71315d9da6d9a3"
-"less@2.6.x || ^2.7.1":
+"less@2.6.x || ^2.7.1", less@latest:
version "2.7.2"
resolved "https://registry.yarnpkg.com/less/-/less-2.7.2.tgz#368d6cc73e1fb03981183280918743c5dcf9b3df"
optionalDependencies: