Skip to content

Commit d33fcd9

Browse files
Dieter LuypaertDeMoorJasper
Dieter Luypaert
andauthored
Support less URL rewrites (#4637)
Co-authored-by: Jasper De Moor <[email protected]>
1 parent e5390f0 commit d33fcd9

File tree

9 files changed

+62
-0
lines changed

9 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require('./index.less');
2+
3+
module.exports = function () {
4+
return 2;
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import "./nested/a.less";
2+
@import "./node_modules/library/b.less";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@font-face {
2+
font-family: "A";
3+
src: url("./a.woff2") format("woff2");
4+
}
5+
6+
.a {
7+
font-family: "A";
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

packages/core/integration-tests/test/integration/less-url-rewrite/node_modules/library/b.less

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/integration-tests/test/integration/less-url-rewrite/node_modules/library/b.woff2

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"private": true
3+
}

packages/core/integration-tests/test/less.js

+33
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,39 @@ describe('less', function() {
147147
);
148148
});
149149

150+
it('should support less url rewrites', async function() {
151+
let b = await bundle(
152+
path.join(__dirname, '/integration/less-url-rewrite/index.js'),
153+
);
154+
155+
assertBundles(b, [
156+
{
157+
name: 'index.js',
158+
assets: ['index.js'],
159+
},
160+
{
161+
name: 'index.css',
162+
assets: ['index.less'],
163+
},
164+
{
165+
type: 'woff2',
166+
assets: ['a.woff2'],
167+
},
168+
{
169+
type: 'woff2',
170+
assets: ['b.woff2'],
171+
},
172+
]);
173+
174+
let output = await run(b);
175+
assert.equal(typeof output, 'function');
176+
assert.equal(output(), 2);
177+
178+
let css = await outputFS.readFile(path.join(distDir, 'index.css'), 'utf8');
179+
assert(css.includes('.a'));
180+
assert(css.includes('.b'));
181+
});
182+
150183
it('should support transforming less with postcss', async function() {
151184
let b = await bundle(
152185
path.join(__dirname, '/integration/less-postcss/index.js'),

packages/transformers/less/src/LessTransformer.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default new Transformer({
2222
urlPlugin({asset}),
2323
resolvePathPlugin({asset, resolve}),
2424
];
25+
config.rewriteUrls = 'all';
2526

2627
if (options.sourceMaps) {
2728
config.sourceMap = {};

0 commit comments

Comments
 (0)