mwstake / mediawiki-component-thirdpartyresources
Provides ResourceLoader module definitions that allow for inclusion of third-party pre-compiled resources (JS/CSS)
Installs: 40 755
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 0
Open Issues: 1
Requires
Requires (Dev)
- jakub-onderka/php-console-highlighter: 0.4.0
- jakub-onderka/php-parallel-lint: 1.0.0
- mediawiki/mediawiki-codesniffer: 29.0.0
- mediawiki/minus-x: 1.0.0
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2024-10-22 09:20:33 UTC
README
ThirdPartyResources for MediaWiki
Provides ResourceLoader module definitions that allow for inclusion of third-party pre-compiled resources (JS/CSS).
This code is meant to be used within the MediaWiki framework. Do not attempt to use it outside of MediaWiki.
Use in a MediaWiki extension
Add "mwstake/mediawiki-component-thirdpartyresources": "~1.0"
to the require
section of your composer.json
file.
Explicit initialization is required. This can be archived by
- either adding
"callback": "mwsInitComponents"
to yourextension.json
/skin.json
- or calling
mwsInitComponents();
within you extensions/skins customcallback
method
See also mwstake/mediawiki-componentloader
.
Optional: Setting up package.json
In MediaWiki extensions/skins, the package.json
is usually just used for CI tasks, like eslint
. Therefore one usually has only the "devDependecies"
entry and the node_modules/
directory is excluded from source code management e.g. via .gitignore
.
If npm
is used to pull in actual dependenies, it is recommended to copy the "dist" file(s) into the resources/
(or modules/
) directory of the extension/skin. This can easily be done by a scripts.postinstall
entry.
Example package.json
"scripts": { "postinstall": "cp node_modules/some-package/dist/some-package.min.js resources/lib/" }, "dependencies": { "some-package": "^1.0.0" }
Setting up the ResourceLoader module
MediaWiki ResourceLoader may corrupt pre-packaged JS/CSS files, as it applies "minification". Also it may lack a proper module.exports
statement, to make the third party code available to the consuming code.
To overcome such issues, use the "class"
property of the "ResourceModule"
definition like this:
"ResourceModules": { "ext.SomePackageComponent": { "class": "MWStake\\MediaWiki\\Component\\ThirdPartyResources\\ResourceLoader\\DistFiles", "packageFiles": [ "lib/some-package.min.js" ] } }, "ResourceFileModulePaths": { "localBasePath": "resources", "remoteExtPath": "MyExtension/resources" },
If a special module.exports
is required, it can be specified in the "module.exports"
property.
"ResourceModules": { "ext.VTreeView": { "class": "MWStake\\MediaWiki\\Component\\ThirdPartyResources\\ResourceLoader\\DistFiles", "module.exports": "SomePackageComponent", "packageFiles": [ "lib/some-package.min.js" ] } },