diff --git a/packages/concat-style-loader/concat.js b/packages/concat-style-loader/concat.js index 000c727a2..2c4c3fddf 100644 --- a/packages/concat-style-loader/concat.js +++ b/packages/concat-style-loader/concat.js @@ -1,8 +1,8 @@ const fs = require('fs'); const path = require('path'); -function concatStyles(content, rootPath) { - const assets = parseImports(content, rootPath).reverse(); +function concatStyles(content, rootPath, loader) { + const assets = parseImports(content, rootPath, loader).reverse(); assets.forEach((asset) => { asset.content = concatStyles(asset.content, asset.path); @@ -19,25 +19,27 @@ function inlineAsset(content, asset) { return content.slice(0, startIndex) + asset.content + content.slice(endIndex); } -function parseImports(content, rootPath) { +function parseImports(content, rootPath, loader) { const matches = getImportStatements(content); return matches.map((match) => { const url = getImportURL(match[0]); const assetPath = path.resolve(path.dirname(rootPath), url); - const content = fetchAssetContent(assetPath); + const content = fetchAssetContent(assetPath, loader); return {path: assetPath, content, match}; }); } -function fetchAssetContent(assetPath) { +function fetchAssetContent(assetPath, loader) { if (!fs.existsSync(assetPath)) { throw new Error( `Concat Style Loader Error: Cannot find asset '${assetPath}'`, ); } + loader && loader.addDependency(assetPath); + return fs.readFileSync(assetPath, 'utf8'); } diff --git a/packages/concat-style-loader/index.js b/packages/concat-style-loader/index.js index a941c38c9..093bd5b2c 100644 --- a/packages/concat-style-loader/index.js +++ b/packages/concat-style-loader/index.js @@ -8,7 +8,7 @@ module.exports = function(content) { const options = getOptions(this); const rootPath = this.resourcePath; - content = concatStyles(content, rootPath); + content = concatStyles(content, rootPath, this); return `module.exports = ${JSON.stringify(content)}`; };