Skip to content

Commit

Permalink
Merge pull request #353 from KristofMorva/resource-root
Browse files Browse the repository at this point in the history
Ability to set prefix for generated asset paths (Fixes #339)
  • Loading branch information
JeffreyWay committed Feb 15, 2017
2 parents 016998d + c1425df commit d779fa4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup/webpack.config.js
Expand Up @@ -130,7 +130,7 @@ module.exports.module = {
loader: 'file-loader',
options: {
name: 'images/[name].[ext]?[hash]',
publicPath: '/'
publicPath: Mix.resourceRoot
}
},

Expand All @@ -139,7 +139,7 @@ module.exports.module = {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]?[hash]',
publicPath: '/'
publicPath: Mix.resourceRoot
}
}
]
Expand Down
1 change: 1 addition & 0 deletions setup/webpack.mix.js
Expand Up @@ -30,6 +30,7 @@ mix.js('src/app.js', 'dist/')
// mix.version(); // Enable versioning.
// mix.disableNotifications();
// mix.setPublicPath('path/to/public');
// mix.setResourceRoot('prefix/for/resource/locators');
// mix.autoload({}); <-- Will be passed to Webpack's ProvidePlugin.
// mix.webpackConfig({}); <-- Override webpack.config.js, without editing the file directly.
// mix.then(function () {}) <-- Will be triggered each time Webpack finishes building.
Expand Down
2 changes: 2 additions & 0 deletions src/Mix.js
Expand Up @@ -25,6 +25,7 @@ class Mix {
this.concat = new Concat(this.events);
this.inProduction = process.env.NODE_ENV === 'production';
this.publicPath = './';
this.resourceRoot = '/';
this.options = {
extractVueStyles: false,
processCssUrls: true
Expand Down Expand Up @@ -189,6 +190,7 @@ class Mix {
].forEach(prop => this[prop] = null);

this.publicPath = './';
this.resourceRoot = '/';
this.js = [];
this.entryBuilder.reset();
this.events = new Dispatcher;
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Expand Up @@ -300,6 +300,18 @@ module.exports.setPublicPath = (path) => {
};


/**
* Set prefix for generated asset paths
*
* @param {string} path
*/
module.exports.setResourceRoot = (path) => {
Mix.resourceRoot = path;

return this;
};


/**
* Merge custom config with the provided webpack.config file.
*
Expand Down

0 comments on commit d779fa4

Please sign in to comment.