GithubHelp home page GithubHelp logo

wkeese / babel-plugin-module-resolver-standalone Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prantlf/babel-plugin-module-resolver-standalone

0.0 1.0 0.0 22 KB

Module resolver plugin for Babel usable in both Node.js the web browser environments

License: MIT License

JavaScript 100.00%

babel-plugin-module-resolver-standalone's Introduction

babel-plugin-module-resolver-standalone

NPM version devDependency Status

A Babel plugin to add a new resolver for your modules when compiling your code using Babel. This plugin allows you to transform the path of each source module using a custom JavaScript function.

This plugin can be used instead of babel-plugin-module-resolver, if the target environment is a web browser using @babel/standalone, with which the original plugin does not work. This plugin supports only the method resolvePath for the time being.

Table of Contents

Installation

This module can be installed in your project using NPM or Yarn. Make sure, that you use Node.js version 6 or newer.

npm i -D babel-plugin-module-resolver-standalone
yarn add babel-plugin-module-resolver-standalone

Babel Configuration Examples

Prepend path to utility modules to be able to import them from utils/... without always providing the actual full path:

{
  plugins: [
    [
      'module-resolver',
      {
        resolvePath: function (sourcePath, currentFile, opts) {
          if (sourcePath.startsWith('utils/')) {
            return '../../'+ sourcePath
          }
        }
      }
    ]
  ]
}

Ensure, that all JavaScript module paths are prefixed by es6!, so that requirejs-babel will be applied by RequireJS to nested modules too:

{
  plugins: [
    'transform-modules-amd',
    [
      'module-resolver',
      {
        resolvePath: function (sourcePath, currentFile, opts) {
          // Avoid prefixing modules handled by other plugins.
          if (sourcePath.indexOf('!') < 0) {
            return 'es6!' + sourcePath;
          }
        }
      }
    ]
  ]
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

License

Copyright (c) 2019 Ferdinand Prantl

Licensed under the MIT license.

babel-plugin-module-resolver-standalone's People

Contributors

prantlf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.