admin管理员组

文章数量:1426034

I am creating a package for ExtJS 6 where I need to include an external JavaScript file as a resource.

I placed the file in the resources folder of my package, but I can't seem to find any documentation on how to use Ext.require() to load this file.

I could use Ext.require(Ext.resolveResource("<@MyPackage>custom") - that downloads and executes the Sencha/build/production/MyApp/classic/resources/MyPackage/custom.js but it also plains that it cannot load the class from this file:

[E] [Loader] The following classes failed to load:
[E] [Loader] Sencha/build/production/MyApp/classic/resources/MyPackage/custom from Sencha/build/production/MyApp/classic/resources/MyPackage/custom.js

Can Ext.require() be used for this purpose or do I have to use Ext.AJAX and create the <script> tag by myself?

I am creating a package for ExtJS 6 where I need to include an external JavaScript file as a resource.

I placed the file in the resources folder of my package, but I can't seem to find any documentation on how to use Ext.require() to load this file.

I could use Ext.require(Ext.resolveResource("<@MyPackage>custom") - that downloads and executes the Sencha/build/production/MyApp/classic/resources/MyPackage/custom.js but it also plains that it cannot load the class from this file:

[E] [Loader] The following classes failed to load:
[E] [Loader] Sencha/build/production/MyApp/classic/resources/MyPackage/custom from Sencha/build/production/MyApp/classic/resources/MyPackage/custom.js

Can Ext.require() be used for this purpose or do I have to use Ext.AJAX and create the <script> tag by myself?

Share Improve this question asked Jan 26, 2016 at 13:20 KnaģisKnaģis 21.5k9 gold badges70 silver badges80 bronze badges 5
  • Have you tried edition app.json? – Dumbledore Commented Jan 26, 2016 at 13:31
  • Since I am creating a package, editing app.json seems wrong as it is outside the package code. – Knaģis Commented Jan 26, 2016 at 13:32
  • Are you creating a new class or overriding existing classes? – Dumbledore Commented Jan 26, 2016 at 13:34
  • new ponents that extend Ext.Component. – Knaģis Commented Jan 26, 2016 at 14:11
  • IMO, you need to add the files as resource in app.json (after the ExtJS bundle, of course), so that you ExtJS can load you package at app start and you can use these class just like an existing class. Second option is that you can use Ext.Loader. However, I'd like to know other people's thoughts/opinions as well. – Dumbledore Commented Jan 26, 2016 at 15:37
Add a ment  | 

2 Answers 2

Reset to default 2

Edit app.json and look for js property or add it in case it is not there.

...
"js": [
    {
        "path": "lib/myExternalLibrary.js",
        "includeInBundle": true
    },
]
...

reference https://docs.sencha./cmd/6.x/microloader.html#js

Maybe its already to late, but this works for ExtJs6 in your package.json

"js" : [{
    "path": "resources/js/OpenLayers.js",
    "bundle": true
}]

本文标签: How to require a custom JavaScript file from ExtJS package resources folderStack Overflow