How to use babel-plugin-module-resolver - 8 common examples

To help you get started, we’ve selected a few babel-plugin-module-resolver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TallerWebSolutions / next-on-drupal / config / babel / babel.common.js View on Github external
const resolveComponentPath = (sourcePath, currentFile, opts) => {
  const defaultPath = resolvePath(sourcePath, currentFile, opts)

  try {
    const resolved = resolve(dirname(currentFile), defaultPath)

    if (statSync(resolved).isDirectory()) {
      const ext = extname(sourcePath) || '.js'
      const index = join(resolved, 'index' + ext)
      const component = join(resolved, basename(resolved) + ext)

      if (!existsSync(index) && existsSync(component)) {
        return component
      }
    }
  } catch (err) {
    // ignore errors, simply return default resolved path.
  }
github tleunen / eslint-import-resolver-babel-module / src / index.js View on Github external
// e.g. in .eslintrc file
        // "import/resolver": {
        //   "babel-module": {
        //     "root": ["./src"],
        //     "extensions": [".js", ".jsx"]
        //   }
        // }
        cwd: options.cwd || projectRootDir,
        root: options.root || [],
        alias: options.alias || {},
        extensions: options.extensions || defaultExtensions,
      },
    );

    const finalSource = stripWebpack(source, pluginOptions.alias);
    const src = resolvePath(finalSource, file, pluginOptions);

    const extensions = options.extensions || pluginOptions.extensions;

    return {
      found: true,
      path: resolve.sync(src || source, {
        ...options,
        extensions,
        basedir: path.dirname(file),
      }),
    };
  } catch (e) {
    return { found: false };
  }
};
github mui-org / material-ui / docs / babel.config.js View on Github external
function resolvePath(sourcePath, currentFile, opts) {
  if (sourcePath === 'markdown') {
    const base = currentFile.substring(__dirname.length).slice(0, -3);
    return `${__dirname}/docs/src/${base}/`;
  }

  return bpmr.resolvePath(sourcePath, currentFile, opts);
}
github Beven91 / react-native-on-web / packages / react-native-on-web-bundler / src / webpack / webpack.server.js View on Github external
resolvePath(sourcePath, currentFile, opts) {
      let name = ModuleResolver.resolvePath(sourcePath, currentFile, opts);
      if (name) {
        let full = path.join(path.dirname(currentFile), name);
        let name2 = path.relative(config.projectRoot, full);
        return name2.indexOf('..' + path.sep) > -1 ? name.replace('../', '') : name;
      }
    },
    'alias': Options.merge({
github expo / expo / react-native-lab / transformer.js View on Github external
function buildModuleResolverPreset() {
  const expoReactNativePath = path.join(__dirname, 'react-native');
  const expoReactPath = path.join(expoReactNativePath, 'node_modules/react');
  return {
    plugins: [
      [
        require('babel-plugin-module-resolver').default,
        {
          alias: {
            react: expoReactPath,
            'react-native': expoReactNativePath,
          },
        },
      ],
    ],
  };
}
github react-navigation / react-navigation / examples / NavigationPlayground / __exponent / transformer.js View on Github external
const buildAliasPreset = (reactNativePath, reactPath) => ({
  plugins: [
    [
      require('babel-plugin-module-resolver').default,
      {
        alias: Object.assign(
          {},
          {
            'react-native': path.resolve(
              `${reactNativePath || './node_modules/react-native'}`
            ),
            react: path.resolve(`${reactPath || './node_modules/react'}`),
          },
          require('babel-preset-exponent').plugins[0][1].alias
        ),
        cwd: path.resolve(__dirname, '..'),
      },
    ],
  ],
});
github zendesk / volunteer_portal / babel.config.js View on Github external
[
        require('@babel/plugin-transform-runtime').default,
        {
          helpers: false,
          regenerator: true,
          corejs: false,
        },
      ],
      [
        require('@babel/plugin-transform-regenerator').default,
        {
          async: false,
        },
      ],
      [
        require('babel-plugin-module-resolver').default,
        {
          root: ['./app/javascript/'],
        },
      ],
    ].filter(Boolean),
  }
}
github ark120202 / babel-lua / packages / babel-plugin-lua-module-resolver / src / index.js View on Github external
pre(file) {
    this.types = types;
    this.moduleResolverVisited = new Set();

    this.normalizedOpts = normalizeOptions(file.opts.filename, this.opts);

    const { luaRoot } = this.opts;
    if (luaRoot == null) throw new Error('Required option `luaRoot` is not defined');

    const optionalResolvePath = this.opts.resolvePath;
    this.normalizedOpts.resolvePath = createResolver(luaRoot, optionalResolvePath);
  },

babel-plugin-module-resolver

Module resolver plugin for Babel

MIT
Latest version published 7 months ago

Package Health Score

82 / 100
Full package analysis