npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sfra-module-loader

v0.1.5

Published

sfra module loader for webpack

Downloads

8

Readme

npm deps tests

sfra-module-loader

A saleforce commerce cloud module loader for webpack based on the cartridge path

Getting Started

To begin, you'll need to install sfra-module-loader:

$ npm install sfra-module-loader --save-dev

Import (or require) the target file(s) in one of the bundle's files in current cartridge:

// bundle file
import mod from '*/component/mod'

Then add the loader to your webpack config. For example:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.(js)$/,
        use: [
          {
            loader: 'sfra-module-loader',
            options: {
              cartridges: [
                'storefront',
                'core'
              ]
            }
          }
        ]
      }
    ]
  }
}

And run webpack via your preferred method. This will load the first found module in cartridge path.

Options

context

Type: String Default: ../

Specifies a cartridges context.

// webpack.config.js
...
{
  loader: 'sfra-module-loader',
  options: {
    cartridges: 'storefront:core',
    context: path.resolve(__dirname, '../')
  }
}
...

cartridges

Type: String|Array Default: ``

The cartridge path

// bundle file
import mod from '*/component/mod'
// webpack.config.js
...
{
  loader: 'sfra-module-loader',
  options: {
    cartridges: [
      'storefront',
      'core'
    ]
  }
}
...

Or using a String:

// bundle file
import mod from '*/component/mod'
// webpack.config.js
...
{
  loader: 'sfra-module-loader',
  options: {
    cartridges: 'storefront:core'
  }
}
...

Loader will scan all cartriges in project repositoty from top most (or left to right) cartridge in cartridge path

cache

Type: Boolean Default: true

If true, loader will scan and store cartridge location on first run and use them for next run

// webpack.config.js
{
  loader: 'sfra-module-loader',
  options: {
    ...
    cache: true
  }
}

alias

Type: Object

If configured, loader will replace all request that star with the alias name with closest existing ancestor module

// webpack.config.js
{
  loader: 'sfra-module-loader',
  options: {
    ...
    alias: {
      core: 'core',
    },
    cartridges: 'storefront:core'
  }
}

To driect request to an ancestor module, use colon : after alias name (e.g, core:abc/mod)

Examples

The following examples show how one might use sfra-module-loader and what the result would be.

// /core/js/components/mod.js 
export default () => {
  console.log('module from core');
}
// /pluggin/js/components/mod.js 
const baseModule = module.superModule; // -> /core/js/components/mod.js

export default () => {
  baseModule();

  console.log('module from pluggin');
}
// /storefront/main.js
import mod1 from '*/components/mod' // -> /pluggin/js/components/mod.js
import mod2 from 'core/components/mod' // -> /pluggin/js/components/mod.js
import mod3 from 'core:components/mod' // -> /core/js/components/mod.js

export default () => {
  mod();
  mod1();
  mod3();
}
// webpack.config.js
{
  loader: 'sfra-module-loader',
  options: {
    alias: {
      core: 'core',
    },
    cartridges: 'storefront:core',
    context: path.resolve(__dirname, '../')
  }
}
# result
module from core

Contributing

Contributing is welcome.