UNPKG

@iamota/iamota-webpack

Version:

Helper tools for Webpack for iamota Framework (WordPress and Shopify)

27 lines (21 loc) 1 kB
// ---------------------------------------------------------------------------- // filename-loader.js // ---------------------------------------------------------------------------- // // Webpack loader to replace `__FILE__` and `__FILE_FULL__` with the actual file name // // ---------------------------------------------------------------------------- /** * Load Dependencies */ const path = require('path'); // filename-loader.js module.exports = function (source) { const filePath = this.resourcePath; // `this.resourcePath` gives the absolute path of the file being processed const fileName = path.basename(filePath); // Extract just the filename using path // Replace `__FILE__` and `__FILE_FULL__` with the actual file name data let modifiedSource = source; modifiedSource = modifiedSource.replace(/__FILE__/g, JSON.stringify(fileName)); modifiedSource = modifiedSource.replace(/__FILE_FULL__/g, JSON.stringify(filePath)); return modifiedSource; };