Skip to content

Add pathPrefix option #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
const vm = require('vm')
const path = require('path')
const {
interpolateName
interpolateName,
getOptions
} = require('loader-utils')

const {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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}'`,
Expand Down