Steven Brookes
Steven Brookes

Reputation: 894

importing .less file from Razor Class Library

I have created a Razor Class Library to be able to distribute some global styles and views across projects, but I can't seem to import my .less files from the Razor Class Library.

In my RCL I have:

Styles
  -Shared
    -layout.less
    -variables.less

In the project referencing the RCL I have:

Styles
  -main.less

main.less only has:

@import "./Shared/variables.less";

When I run a build via webpack I get errors that it cannot resolve ./Shared/variables.less, but it works fine if I copy the Shared directory from the RCL into the project referencing it.

I have the BuildAction for the RCL .less files set to Content, is there anything I am missing, or is this something that is not possible?

Upvotes: 0

Views: 382

Answers (2)

Lyon
Lyon

Reputation: 606

You could possibly manually manage the build order and run a powershell script post build (making sure that the correct dll is building first) and interrogate the dll and extract the required files (?) into the correct folders in wwwroot, or wherever, before the webpack build. I think that happens after the projects are built, but I'm not an expert on webpack either and I haven't actually tried this.

Also technically if you want any static or view files to be embedded in the dll you would select "Embedded resource", well that is how I've done it in the past.

Upvotes: 0

Chris Pratt
Chris Pratt

Reputation: 239470

It's some what possible, but not for specifically what you're trying to do here. An RCL is ultimately a DLL, so the only thing you can include in it, is things that can be "compiled" into that. I say compiled with quotes, because static files can be included as embedded resources, so while they're not themselves compiled, they are still literally being embedded into the resulting DLL. With the ManifestEmbeddedFileProvider, the app using your RCL can read from these embedded resources as if they were literally on the filesystem.

However, and importantly, they are not on the the filesystem, which means using things like webpack is a 100% no-go. What you'll need to do is actually do a webpack build as part of the RCL, and then embed the resulting static resources in the RCL. Your app, then, can have its own webpack build for it's own resources, but you won't be able to combine primitives from the RCL with primitives from your app.

Upvotes: 2

Related Questions