@midiu/cartridge-resolver
v1.0.1
Published
Webpack Plugin: Provide the cartridge inheritance behavior same as Demandware server side scripts.
Downloads
5
Maintainers
Readme
Webpack: Cartridge Resolver Plugin
Provide the cartridge inheritance behavior same as Demandware server side scripts with additional functionalities supports.
Installation
npm install --save-dev @midiu/cartridge-resolver
Usage
Register plugin to your webpack.config.js
.
For more informations, please have a look inside class CartridgeResolverPlugin
const cwd = process.cwd();
const CartridgeResolverPlugin = require('@midiu/cartridge-resolver');
module.exports = {
// your other webpack configs...
resolve: {
plugins: [new CartridgeResolverPlugin({
your_storefront: path.resolve(cwd, 'cartridges/your_storefront/cartridge/client'),
your_storefront_style_guide: path.resolve(cwd, 'cartridges/your_storefront_style_guide/cartridge/client'),
plugin_wishlists: path.resolve(cwd, 'vendors/plugin_wishlists/cartridge/client'),
app_storefront_style_guide: path.resolve(cwd, 'cartridges/app_storefront_style_guide/cartridge/client'),
app_storefront_core: path.resolve(cwd, 'cartridges/app_storefront_core/cartridge/client'),
app_storefront_base: path.resolve(cwd, 'cartridges/app_storefront_base/cartridge/client')
}, {
base: 'app_storefront_base',
core: 'app_storefront_core'
})]
}
}
Asset Solving Rules
+ ----------- + ----- + --------------------------- +
| Cartridge | Alias | Assets |
+ ----------- + ----- + --- - --- - --- - --- - --- +
| cartridge_a | a | 1 | | 3 | | 5 |
| cartridge_b | b | | 2 | 3 | 4 | |
| cartridge_c | | | | | 4 | 5 |
| cartridge_d | d | 1 | 2 | | | 5 |
+ ----------- + ----- + --------------------------- +
- Cartridge lookup priority follow the order of registered cartridges object ASC.
- Use special symbols to require the target asset.
^
flag used to lookup super module asset, Example:require('^')
- require same asset from lower priority cartridgesrequire('^/some/asset')
- requiresome/asset
from lower priority cartridgesrequire('^:some/asset')
- same as above, requiresome/asset
from lower priority cartridges
*
flag used to lookup across registered cartridgesrequire('*/some/asset')
- requiresome/asset
from any cartridgesrequire('*:some/asset')
- same as above, requiresome/asset
from any cartridges
~
flag used to lookup asset in current cartridgerequire('~/some/asset')
- requiresome/asset
from current cartridgerequire('~:some/asset')
- same as above, requiresome/asset
from current cartridge
superModule
are modules loaded from lower priority cartridges . For example: incartridge_b:2.js
, require super module mean lookup for asset2.js
in 2 other lower prioritycartridge_c
andcartridge_d
. The result will becartridge_d:2.js
- Absolute cartridge can be used follow pattern:
{cartridge_name}:{asset_path}
or{alias_name}:{asset_path}
. Solving theasset_path
from exactlycartridge_name
oralias_name
. For example:require('cartridge_d:1')
will returncartridge_d/1.js
require('c:5')
will returncartridge_c/5.js
- Named alias asset:
- difference path with origin will be solve using asterisk
*
behavior. For example:- From
cartridge_a/1.js
-require('d/2')
which looking for2.js
usingd
alias (difference path with origin1.js
) will equalrequire('*/2')
and returncartridge_b/2.js
(since thecartridge_b
has higher priority thancartridge_d
) - From
cartridge_b/2.js
-require('c/5')
which looking for5.js
usingc
alias (difference path with origin2.js
) will equalrequire('*/5')
and returncartridge_a/5.js
(since thecartridge_a
has higher priority thancartridge_c
)
- From
- same path with origin will be solve using super module
^
behavior: For example:- From
cartridge_a/1.js
-require('a/1')
which looking for1.js
usinga
alias (same path with origin1.js
) will equalrequire('^/1')
and returncartridge_d/1.js
- From
- difference path with origin will be solve using asterisk
- By default, an asset will be lookup across cartridges and return the fist found. Except super module and absolute cartridge path. For example: in
cartridge_a:1.js
, require relative./2
asset will return the first asset found from cartridge path. The result will becartridge_b:2.js
- Required asset same path with the origin will considered as super module. For example: in
cartridge_a:1.js
, all requirementsrequire('^')
orrequire('^:1')
orrequire('^/1')
orrequire('.')
orrequire('./1')
will looking for1.js
from lower priority cartridges . The result will becartridge_d:1.js