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

Q: MVC: include jsvascript as module #21679

Open
leonkosak opened this issue Dec 19, 2024 · 3 comments
Open

Q: MVC: include jsvascript as module #21679

leonkosak opened this issue Dec 19, 2024 · 3 comments

Comments

@leonkosak
Copy link
Contributor

For MVC project, how to properlja import devextreme-aspnet-data-nojquery library inside abp.resourcemapping.js and initialized in .cshtml?
Error in javascript console: Uncaught This script should be used with an AMD or CommonJS loader

I know that MVC project includes jQuery, but I prefer not using if possible.
Thank you.

@maliming
Copy link
Member

hi

You can create a new npm package and a ScriptContributor in your module.

package.json

{
  "version": "1.0.0",
  "name": "yourmodulename/devextreme-aspnet-data-nojquery",
  "publishConfig": {
    "access": "public"
  },
  "dependencies": {
    "@abp/core": "~9.0.2",
    "devextreme-aspnet-data-nojquery": "~5.0.0"
  }
  //...
}

abp.resourcemapping.js

module.exports = {
    mappings: {
        "@node_modules/devextreme-aspnet-data-nojquery/*.*": "@libs/yourmodulename/devextreme-aspnet-data-nojquery/"
    }
}
[DependsOn(typeof(CoreScriptContributor))]
public class YourModuleNameDevextremeScriptContributor : BundleContributor
{
    public override void ConfigureBundle(BundleConfigurationContext context)
    {
        context.Files.AddIfNotContains("/libs/yourmodulename/devextreme-aspnet-data-nojquery/index.js");
    }
}

Add your npm package to package.json of your host/app project.

Run the abp install-libs command. The Devextreme js will/should copy to the libs folder.

See:

https://github.com/abpframework/abp/tree/dev/npm/packs/signalr
https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Packages/Volo/Abp/AspNetCore/Mvc/UI/Packages/SignalR/SignalRBrowserScriptContributor.cs#L8-L15

@leonkosak
Copy link
Contributor Author

leonkosak commented Dec 20, 2024

I'll try @maliming.
What about adding this library in package.json inside abp solution along @volo packages? Is creating custom npm package and publishing to npm really necessary?

@maliming
Copy link
Member

If the devextreme-aspnet-data-nojquery is popular, we can add it as an abp npm package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants