File size: 1,416 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | /**
* Return a Webpack loader configuration object containing for JavaScript transpilation.
* @param {Object} _ Options
* @param {number} _.workerCount Number of workers that are being used by the thread-loader
* @param {string} _.configFile Babel config file
* @param {string} _.cacheDirectory Babel cache directory
* @param {string} _.cacheIdentifier Babel cache identifier
* @param {boolean} _.cacheCompression Whether to apply gzip compression to the cached files (defauls to true)
* @param {RegExp|Function} _.exclude Directories to exclude when looking for files to transpile
* @param {RegExp|Function} _.include Directories to inclued when looking for files to transpile
* @param {string[]} _.presets Babel presets
* @param {string[]} _.plugins Babel plugins (optional)
* @returns {Object} Webpack loader object
*/
module.exports.loader = ( {
workerCount,
configFile,
cacheDirectory,
cacheIdentifier,
cacheCompression = true,
exclude,
include,
presets,
plugins,
} ) => ( {
test: /\.[jt]sx?$/,
include,
exclude,
use: [
{
loader: require.resolve( 'thread-loader' ),
options: {
workers: workerCount,
},
},
{
loader: require.resolve( 'babel-loader' ),
options: {
configFile,
babelrc: false,
cacheDirectory,
cacheIdentifier,
cacheCompression,
presets,
plugins,
},
},
],
} );
|