less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
16.99k stars 3.41k forks source link

less version: 4.1.3 #3753

Closed Zebzhong closed 1 year ago

Zebzhong commented 1 year ago

less version: 4.1.3 node version: 14.x os: windows 10

code

const less = require("less");

let lessStr = `
@color1: 'blue';
@imgUrl: '';
@furl: 'https://qq.com';

body{
  color: @color1;
}

.myImg {
  background: url('@{imgUrl}') no-repeat;
  background-size: contain;
  width: 200px;
  height: 200px;
}

@font-face {
  font-family: 'zbtest';
  src: "url('@{furl}')";
}
.root {
  font-family: 'zbtest';
}
`

less
  .render(lessStr, {
    modifyVars: {
      color1: 'skyblue',
      imgUrl: '../test/qe.png',
      furl: "https://www.baidu.com"
    },
  })
  .then((res) => {
    console.log(res);
  });

result image

hope Can replace externals url variables correctly, Thanks

Originally posted by @Zebzhong in https://github.com/less/less.js/discussions/3752

Zebzhong commented 1 year ago

repeat