Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor] JS isolation improvement - Colocate CS, CSS and JS files #26145

Closed
daniel-p-tech opened this issue Sep 21, 2020 · 12 comments
Closed

[Blazor] JS isolation improvement - Colocate CS, CSS and JS files #26145

daniel-p-tech opened this issue Sep 21, 2020 · 12 comments
Assignees
Labels
affected-most This issue impacts most of the customers area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-jsinterop This issue is related to JSInterop in Blazor severity-minor This label is used by an internal tool
Milestone

Comments

@daniel-p-tech
Copy link

daniel-p-tech commented Sep 21, 2020

Hi,

When the work on JS isolation was first announced, I was expecting something similar to CSS isolation where I would be able to create ComponentXYZ.razor.js file. Apparently other developers are in favor of this idea as well:

#23560

I'd like to take this approach further as suggested in a separate ticket:
https://github.com/dotnet/aspnetcore/issues/24943

I really believe there is a great benefit in organizing a large project this way, it's a lot more convenient to find JS/CSS files related to a component rather than chasing them down in a separate folder. This is exactly how we organize our large WebForms projects as well, so I'm speaking from experience.

Thank you for your consideration!

@captainsafia captainsafia added the area-blazor Includes: Blazor, Razor Components label Sep 21, 2020
@captainsafia captainsafia added this to the Backlog milestone Sep 22, 2020
@ghost
Copy link

ghost commented Sep 22, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@lonix1
Copy link
Contributor

lonix1 commented Sep 24, 2020

Some context from that other issue.

@SteveSandersonMS wrote:

The limitation is the .js file needs to go in wwwroot rather than side-by-side with the component. Perhaps that's something we could enhance in the future but for now put the .js file into some directory structure within wwwroot.

@Amine-Smahi wrote:

The problem is the location of the js file. It would be perfect if we had the ability to create a folder for each component that contain the css, js and razor together just like angular.

@egil provided a temporary workaround:

this should be doable by a build script/msbuild step, that finds all .js/.ts files in a Blazor class lib/app and copies them to wwwroot at build time

@daniel-p-tech daniel-p-tech changed the title [Blazor] Suggestion for JS isolation improvement [Blazor] JS isolation improvement - Colocate CS, CSS and JS files Sep 24, 2020
@git-net
Copy link

git-net commented Sep 25, 2020

maybe we can use vs webcompiler plugin.
compilerconfig.json {
"outputFile": "wwwroot/js/a.razor.js",
"inputFile": "Pages/a.razor.js"
}

@SteveSandersonMS SteveSandersonMS added affected-most This issue impacts most of the customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool labels Oct 6, 2020 — with ASP.NET Core Issue Ranking
@EngstromJimmy
Copy link

We can use the Library Manager to copy the files, I just wrote a blog post on that =)

The only down-side I have found is that the files are copied on Build, if you don't change any files that are actually built, the files won't get updated.

@GeorgeS2019
Copy link

Any feedback on making Blazor JavaScript Isolation to work with importing module consisting of a list of require statements for NodeModules (CommonJS)? Is it possible to use Browserify to bundle it for import in the case of JS Isolation? Kind of new to this.

How to make Browserify compatible with Blazor JavaScript Isolation?

@SteveSandersonMS
Copy link
Member

@GeorgeS2019 Thanks for contacting us. Your support question is separate from this issue, so rather than having this thread get side-tracked, could you please post a new issue? Thanks!

@GeorgeS2019
Copy link

GeorgeS2019 commented Nov 12, 2020

@SteveSandersonMS Got it :-)

FYI => I found this, the plan to bridge the CSJ and ESM gap

@paulguz
Copy link

paulguz commented Jan 22, 2021

+1 for this. In addition to co-location, I'd like to see the module defined in the razor.js being automatically available as a Module property in the C# razor code.

@javiercn javiercn added feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) feature-blazor-jsinterop This issue is related to JSInterop in Blazor and removed feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) labels Apr 20, 2021
@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, 6.0-preview6 May 17, 2021
@pranavkm pranavkm self-assigned this May 19, 2021
@pranavkm pranavkm assigned javiercn and unassigned pranavkm May 27, 2021
@ghost ghost added the Working label May 27, 2021
@javiercn javiercn removed this from the 6.0-preview6 milestone Jun 14, 2021
@LaughingJohn
Copy link

It would be great to have this in Razor Pages as well. Consistency is always good for productivity.
I know CSS isolation in Razor Pages is coming in 6.0 but if JavaScript could be supported in a similar way in both Razor Pages and Blazor it would be perfect. Apologies if this is planned and I missed it...

@javiercn
Copy link
Member

This is in the works for both Blazor and MVC/Razor pages

@LaughingJohn
Copy link

This is in the works for both Blazor and MVC/Razor pages

This is very good news indeed! Thanks @javiercn!

@javiercn
Copy link
Member

done in dotnet/sdk#19270

@ghost ghost added Done This issue has been fixed and removed Working labels Aug 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-most This issue impacts most of the customers area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-jsinterop This issue is related to JSInterop in Blazor severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests