less / less.js

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

less import path resolver #3639

Closed doiya46 closed 3 years ago

doiya46 commented 3 years ago

In my case, I create main file: src/app/styles/main.less

@import 'antd/lib/style/themes/default.less';
@import 'antd/dist/antd.less';
@import '@ant-design/pro-table/dist/table.less';

and in @ant-design/pro-table/dist/table.less used @import '~...... like:

//Its used '~antd....'
@import '~antd/es/style/themes/default.less';

@pro-table-prefix-cls: ~'@{ant-prefix}-pro-table';
....
...

So when I used the command line in package.json

"scripts": {
  "less:build": "lessc --js --rewrite-urls=all --include-path=node_modules src/app/styles/main.less src/app/styles/main.css"
},

It will throw error:

FileError: '~antd/es/style/themes/default.less' wasn't found. Tried - /home/mi/Documents/work/react-demo/node_modules/@ant-design/pro-table/es/~antd/es/style/themes/default.less

The path node_modules/@ant-design/pro-table/es/~antd/es/style/themes/default.less should be node_modules/antd/es/style/themes/default.less. How can I use command line and resolve this problem?

iChenLei commented 3 years ago

For less native https://lesscss.org/usage/#less-options-include-paths

For webpack https://github.com/webpack-contrib/less-loader#imports