babel-plugin-try-import

0.0.3 • Public • Published

babel-plugin-try-import

try import module in webpack

what does this plugin do

convert

let react = tryImport('react');

into

let react = function () {
  let temp;
 
  try {
    temp = require('react').default;
  } catch (error) {}
 
  return temp;
}()

so that webpack won't throw error while react is not exist

convert

let hasReact = hasModule('react');

into

let hasReact = function () {
  let temp = false;
 
  try {
    require.resolveWeak('react');
 
    temp = true;
  } catch (error) {}
 
  return temp;
}()
 

so that you can check if a module exists

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    2
  • 0.0.2
    2
  • 0.0.1
    1

Package Sidebar

Install

npm i babel-plugin-try-import

Weekly Downloads

5

Version

0.0.3

License

MIT

Unpacked Size

5.25 kB

Total Files

4

Last publish

Collaborators

  • laincarl