generate-import.js 470 B

12345678910111213141516
  1. const loaderDefaults = require('../config').loader;
  2. const stringify = require('./stringify');
  3. /**
  4. * @param {string} symbol - Symbol name
  5. * @param {string} module - Module name
  6. * @param {boolean} esModule
  7. * @return {string}
  8. */
  9. function generateImport(symbol, module, esModule = loaderDefaults.esModule) {
  10. return esModule ?
  11. `import ${symbol} from ${stringify(module)}` :
  12. `var ${symbol} = require(${stringify(module)})`;
  13. }
  14. module.exports = generateImport;