Miss any of our Open RFC calls?Watch the recordings here! »

babel-plugin-sfcc-modules

1.0.4 • Public • Published

NPM version Downloads Dependencies star this repo fork this repo Build Status Coverage Status Code Style

babel-plugin-sfcc-modules

Babel plugin to handle non-standard module paths used by Salesforce Commerce Cloud (SFCC)

Server-side code for Salesforce Commerce Cloud uses non-standard module resolution patterns:

  • first matching cartridge from cartridge path
require('*/cartridge/scripts/foo')
  • current cartridge
require('~/cartridge/scripts/bar')

Also there is a non-standard extension

module.superModule

to reference the next match in cartridge path for the current module.

Node.js does not have solutions for these cases.. This can cause problems when you need to run this code in a Node.js environment. The most common case should be for unit testing.

This plugin removes the pain of dealing with modules like proxyquire or sandboxed-module.

Install

$ yarn add babel-plugin-sfcc-modules --dev

Usage

Add to your Babel configuration:

"plugins"[
  ["babel-plugin-sfcc-modules", {
    "cartridgePath": [
      "app_brand",
      "app_core",
      "app_storefront_base"
    ],
    "basePath": "./path/to/cartridges"
  }]
]

Options

Option Type Description
cartridgePath Array the cartridge path used for lookup
basePath string path to the folder containing the cartridges

️️⚠️️️️⚠️⚠️ Warning ⚠️⚠️⚠️

kitten.png

You shouldn't use it for frontend code. There are better alternatives to deal with a cartridge path, NODE_PATH and the handling of frontend assets in sgmf-scripts.

In my opinion the best way to handle frontend code is to have a clean configuration of Webpack aliases.

The cartridge path concept isn't common for Node.js/frontend code. This plugin will work for it but I won't officially support it.

License

MIT © 2020 Jens Simon

Install

npm i babel-plugin-sfcc-modules

DownloadsWeekly Downloads

15

Version

1.0.4

License

MIT

Unpacked Size

10.2 kB

Total Files

6

Last publish

Collaborators

  • avatar