-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 pass less @imports as dependencies to svelte
- Loading branch information
1 parent
9dd53d8
commit 55e9d28
Showing
2 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
const less = require('less/lib/less-node') | ||
|
||
module.exports = ({ content, filename, options }) => { | ||
return less | ||
.render(content, { | ||
sourceMap: {}, | ||
...options, | ||
}) | ||
.then(output => ({ | ||
code: output.css, | ||
map: output.map, | ||
})) | ||
module.exports = async ({ content, filename, options }) => { | ||
const { css, map, imports } = await less.render(content, { | ||
sourceMap: {}, | ||
filename, | ||
...options, | ||
}) | ||
|
||
return { | ||
code: css, | ||
map, | ||
dependencies: imports, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { resolve } = require('path') | ||
const getAutoPreprocess = require('../../src') | ||
const { preprocess } = require('../utils.js') | ||
|
||
describe('transformer - less', () => { | ||
it('should return @imported files as dependencies', async () => { | ||
const template = `<style lang="less">@import "fixtures/style.less";</style>` | ||
const opts = getAutoPreprocess() | ||
const preprocessed = await preprocess(template, opts) | ||
expect(preprocessed.dependencies).toContain( | ||
resolve(__dirname, '..', 'fixtures', 'style.less'), | ||
) | ||
}) | ||
}) |