Anidetrix / rollup-plugin-styles

🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
https://anidetrix.github.io/rollup-plugin-styles
MIT License
243 stars 43 forks source link

less options. provided `paths` do not work. #125

Closed argesoft closed 3 years ago

argesoft commented 4 years ago

When I provide paths in the less loader options, loader does not take it into account (or does not receive it). Other parameters of options work as expected, but paths somehow does not. When I import file only by its name (as it can be located in different folders depending on config) less loader does not scan provided paths and returns error (plugin styles) Error: Cannot find module './config.less' from '--__dirname--\src\'.

To reproduce:

package.json

{
  "devDependencies": {
    "less": "^3.11.3",
    "rollup": "^2.18.1",
    "rollup-plugin-styles": "^3.10.0"
  }
}

rollup.config.js

const styles = require("rollup-plugin-styles");

module.exports = {
    input: "./src/index.less",
    plugins: [
        styles({
            less: {
                paths: [
                    "./src/config",
                    `${__dirname}/src/config`
                ]
            }
        })
    ]
}

./src/index.less

@import "config.less";

.test {
    color:black;
}

./src/config/config.less

.test {
    color:red;
}

The same scenario works for other less plugins. Am I doing something wrong?

Tested on windows 10, node v12.18.1

argesoft commented 4 years ago

Maybe this explains better https://repl.it/@argesoft/rollup-styles-test

Anidetrix commented 4 years ago

Hi @argesoft, sorry for the late response.

I believe the issue is that since the plugin uses custom Less importer paths are not respected properly, will fix that and let you know!

argesoft commented 4 years ago

Thank you @Anidetrix Yes, the problem is related with custom importer. I've commented line 32 in the importer source and the issue resolved. But now I found a different problem.

@font-face {
    font-family: 'PT Sans';
    font-style: normal;
    font-weight: 400;
--->>   src: local('PT Sans'), local('PTSans-Regular'),  url('fonts/PTS-webfont.woff') format('woff');
}

When there is a src attribute mixed with local, then url is not processed at all. Even url->resolve option does not see it.

kaiyoma commented 3 years ago

I just ran into this today and it would be nice to have this working so I don't have lots of ../../../-style imports in my code. Can we get a fix please?

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 3.12.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

StreetStrider commented 11 months ago

@Anidetrix, Hello. I can't find comprehensive description of how certain loaders (first, less in my case) are configured. The readme says that they just work. What if I need to provide custom vars to less or configure it in any other way? Same for other loaders.

Btw, the api reference link in the readme is broken. I've located less part manually, but it seemes to be autogenerated stub.

StreetStrider commented 11 months ago

I've consulted types.ts for all required information.