Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 5ddcc26

Browse files
authored
Fix 97, Import files in less (#98)
* Add tests for import style * Add parent directory to paths * Fix import statement
1 parent 240c0f7 commit 5ddcc26

File tree

12 files changed

+76
-24
lines changed

12 files changed

+76
-24
lines changed

src/style/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { writeFile, mkdirSync as mkdir, existsSync as exists } from 'fs'
22
import { dirname, isAbsolute, resolve as resolvePath } from 'path'
33
import compileCSS from './css'
44
import compileSCSS from './scss'
5-
import compileLESS from './less'
5+
import compileLESS from './less/index'
66
import compileSTYLUS from './stylus'
77

88
const compilers = {

src/style/less.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/style/less/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import path from 'path'
2+
3+
export default async function (style, options) {
4+
const less = require('less')
5+
const config = {
6+
plugins: [],
7+
paths: [],
8+
sourceMap: {
9+
sourceMapFullFilename: style.id,
10+
sourceMapFileInline: false
11+
},
12+
...options.less
13+
}
14+
15+
config.paths.unshift(path.dirname(style.id))
16+
17+
const { css, map } = await less.render(
18+
'data' in options.less ? `${options.less.data}\n${style.code}` : style.code, config
19+
)
20+
21+
style.$compiled = {
22+
code: css.toString(),
23+
map: map.toString()
24+
}
25+
26+
return style
27+
}

test/expects/import-less.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.hello {
2+
color: red;
3+
}

test/expects/import-less.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var importLess = { template: "<div class=\"hello\"></div>",};
2+
3+
export default importLess;

test/expects/import-scss.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.hello {
2+
color: red; }

test/expects/import-scss.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var importScss = { template: "<div class=\"hello\"></div>",};
2+
3+
export default importScss;

test/fixtures/import-less.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div class="hello"></div>
3+
</template>
4+
5+
<script>
6+
export default {}
7+
</script>
8+
9+
<style lang="less">
10+
@import './some.less';
11+
</style>

test/fixtures/import-scss.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div class="hello"></div>
3+
</template>
4+
5+
<script>
6+
export default {}
7+
</script>
8+
9+
<style lang="scss">
10+
@import './some.scss';
11+
</style>

test/fixtures/some.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@var: red;
2+
3+
.hello {
4+
color: @var;
5+
}

test/fixtures/some.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$var: red;
2+
3+
.hello {
4+
color: $var;
5+
}

test/test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ function test(name) {
4949

5050
// Check css output
5151
if ([
52-
'style',
5352
'css-modules',
5453
'css-modules-static',
54+
'import-scss',
55+
'import-less',
56+
'less',
57+
'pug',
5558
'scoped-css',
5659
'scoped-css-with-no-auto-style',
5760
'scss',
58-
'pug',
59-
'less',
61+
'style',
6062
'stylus'
6163
].indexOf(name) > -1) {
6264
var css = read('expects/' + name + '.css')

0 commit comments

Comments
 (0)