importRewrites
is a new feature in steal config. It is similar tomap
with these differences:- it is always scoped to an npm package
- it does a straight text replacement of imports prior to normalizing
Here's a practical example: given an old jQueryUI widget, which we'll call this-old-jquery-ui-plugin
, has a file that references an old jQueryUI naming convention for the widget library:
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'jquery.ui.widget'
], factory);
}
However, we are using a jquery-ui version that has been published with a different file structure, and jquery.ui.widget.js
is no longer a valid file path. We want that import to point to the prior-to-normalized path jquery-ui/ui/widget.js
instead. To do this, add the following to the steal
section in package.json
:
"importRewrites": {
"this-old-jquery-ui-plugin": {
"jquery.ui.widget": "jquery-ui/ui/widget"
}
}
With this config, all of the imports of jquery.ui.widget
in this npm package will be renamed to jquery-ui/ui/widget
and then normalized to e.g. [email protected]#ui/widget
.
Note that wildcards are not supported in importRewrites
; only exact string matches of import specifiers will be replaced.
PR: #1522
Also in this release: