Skip to content

laincarl/babel-plugin-try-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

在webpack中引用“不一定存在”的包

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published