From e16cb6490b006c9060ce6b52410f9de605e191b7 Mon Sep 17 00:00:00 2001 From: Jamie Treworgy Date: Thu, 4 Jan 2018 13:14:30 -0500 Subject: [PATCH] Add pathPrefix option --- loader.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/loader.js b/loader.js index 94e0e80..c601e4a 100644 --- a/loader.js +++ b/loader.js @@ -5,7 +5,8 @@ const { const vm = require('vm') const path = require('path') const { - interpolateName + interpolateName, + getOptions } = require('loader-utils') const { @@ -39,6 +40,8 @@ const rndPlaceholder = * @param {string} content - the module's src */ function cssVisorLoader(content) { + const loaderOptions = getOptions(this); + const pathPrefix = loaderOptions && loaderOptions.pathPrefix || ''; const callback = this.async(); const publicPath = this.options.output.publicPath const dependencies = []; @@ -117,10 +120,10 @@ function cssVisorLoader(content) { this.options.context, path.dirname(this.resourcePath) ).replace(/\\/g, '/') - const staticPath = path.posix.join(basedir, hashedName) - const staticPathUnhased = path.posix.join(basedir, filename) + const staticPath = path.posix.join(pathPrefix, basedir, hashedName) + const staticPathUnhased = path.posix.join(pathPrefix, basedir, filename) - // Nothing fancy, we're just appending HMR code to whatever css-loader emitted + // Nothing fancy, we're just appending HMR code to whatever css-loader emitted const src = new ConcatSource( content, [ `var filename = '/${staticPathUnhased}'`,