Skip to content

Commit

Permalink
Support less URL rewrites (#4637)
Browse files Browse the repository at this point in the history
Co-authored-by: Jasper De Moor <[email protected]>
  • Loading branch information
Dieter Luypaert and DeMoorJasper authored May 21, 2020
1 parent e5390f0 commit d33fcd9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('./index.less');

module.exports = function () {
return 2;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "./nested/a.less";
@import "./node_modules/library/b.less";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@font-face {
font-family: "A";
src: url("./a.woff2") format("woff2");
}

.a {
font-family: "A";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"private": true
}
33 changes: 33 additions & 0 deletions packages/core/integration-tests/test/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ describe('less', function() {
);
});

it('should support less url rewrites', async function() {
let b = await bundle(
path.join(__dirname, '/integration/less-url-rewrite/index.js'),
);

assertBundles(b, [
{
name: 'index.js',
assets: ['index.js'],
},
{
name: 'index.css',
assets: ['index.less'],
},
{
type: 'woff2',
assets: ['a.woff2'],
},
{
type: 'woff2',
assets: ['b.woff2'],
},
]);

let output = await run(b);
assert.equal(typeof output, 'function');
assert.equal(output(), 2);

let css = await outputFS.readFile(path.join(distDir, 'index.css'), 'utf8');
assert(css.includes('.a'));
assert(css.includes('.b'));
});

it('should support transforming less with postcss', async function() {
let b = await bundle(
path.join(__dirname, '/integration/less-postcss/index.js'),
Expand Down
1 change: 1 addition & 0 deletions packages/transformers/less/src/LessTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default new Transformer({
urlPlugin({asset}),
resolvePathPlugin({asset, resolve}),
];
config.rewriteUrls = 'all';

if (options.sourceMaps) {
config.sourceMap = {};
Expand Down

0 comments on commit d33fcd9

Please sign in to comment.