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

babel-plugin-import-customization

v1.0.4

Published

This plugin provides the ability to customize importing files by file name suffix, this plugin can also be used for React-Native. This plugin allows you to create white label applications by allowing you to create a core app with different functionalit

Downloads

19

Readme

babel-plugin-import-customization

This plugin provides the ability to customize importing files by file name suffix, this plugin can also be used for React-Native.
This plugin allows you to create white label applications by allowing you to create a core app with different functionalities\configurations seprarated into dedicated files which will be replaced according to the desired app flavor.

usage in .babelrc

Option 1:
"plugins": [["import-customization", {"suffix": ["myCustomization"]}]]
Option 2:
"plugins": [["import-customization", {"env": "suffixName"}]]

Example

assuming we have the current structure:

src  
  App.js  
  SomeComponent.js  
  SomeComponent.myCustomization.js  

SomeComponent.js - Original Component

  export default class SomeComponent extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
            Hello I am Some Component
        </Text>
      </View>
    );
  }

SomeComponent.myCustomization.js - Component Customization

  // you can inject the original component to custom component in order to extend or use composition
  import SomeComponent from './SomeComponent';
  export default class MyCustomComponent extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
             Hello I am Some Custom Component and below is the original:
        </Text>
          <SomeComponent />
      </View>
    );
  }
}

App.js - Application

  import SomeComponent from './SomeComponent';
  render() {
    return (
      <SomeComponent />
    );
  }
}

without plugin the result would be:
Hello I am Some Component

When building with the plugin the result would be:
Hello I am Some Custom Component and below is the original:
Hello I am Some Component

File suffix configuration

There are two ways to tell the plugin which fileSuffix to take:

  1. Plugin configuration
    "plugins": [["import-customization", {"suffix": ["myCustomization"]}]] This will hardcode the customization key to "myCustomization".
  2. Dynamically by telling the plugin at what env configuration to examine:
    this configration take precedence over the one above.
    "plugins": [["import-customization", {"env": "suffixName"}]] This allows you to create env variable named suffixName and it's value will be used by the plugin as the file suffixes to take.

Usage in react-native script with env configuration

I suggest to use it with cross-env module, so just "npm i cross-env" module before. and then in package.json add script


  "scripts": {
    "android:build:dev:myCustApp": "cross-env-shell APP_NAME=myCustApp \"cd android && gradlew assembleDevRelease\""
   }

If you you already start a react native packager make sure to start it again with cache-reset since webpack build is cached. to do it just run

node node_modules/react-native/local-cli/cli.js start --reset-cache

Note

I gave react example but this plugin can be used for any javascipt code which uses babel. This also support if you use require and not import