1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const { webpackVersion } = require('../globals');
- /**
- * @callback EvaluateToString
- * @param {string} value
- * @returns {function(*): *}
- */
- /**
- * @callback ToConstantDependency
- * @param {*} parser
- * @param {string} value
- * @param {string[]} [runtimeRequirements]
- * @returns {function(*): boolean}
- */
- /**
- * @typedef {Object} ParserHelpers
- * @property {EvaluateToString} evaluateToString
- * @property {ToConstantDependency} toConstantDependency
- */
- /**
- * Gets parser helpers for specific webpack versions.
- * @returns {ParserHelpers} The needed parser helpers.
- */
- function getParserHelpers() {
- if (webpackVersion === 4) {
- const {
- evaluateToString,
- toConstantDependencyWithWebpackRequire,
- } = require('webpack/lib/ParserHelpers');
- return {
- evaluateToString,
- toConstantDependency: toConstantDependencyWithWebpackRequire,
- };
- }
- if (webpackVersion === 5) {
- return require('webpack/lib/javascript/JavascriptParserHelpers');
- }
- }
- module.exports = getParserHelpers;
|