Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit a95ce1e

Browse files
committed
allow to pass options and overwride publicPath
fixes #27
1 parent 8d0b88f commit a95ce1e

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

example/webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ module.exports = {
1515
loaders: [
1616
{ test: /\.css$/, loader: ExtractTextPlugin.extract(
1717
"style-loader",
18-
"css-loader?sourceMap"
18+
"css-loader?sourceMap",
19+
{
20+
publicPath: "../"
21+
}
1922
)},
2023
{ test: /\.png$/, loader: "file-loader" }
2124
]
2225
},
2326
plugins: [
24-
new ExtractTextPlugin("[name].css?[hash]-[chunkhash]-[name]", {
27+
new ExtractTextPlugin("css/[name].css?[hash]-[chunkhash]-[name]", {
2528
disable: false,
2629
allChunks: true
2730
}),

index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ function ExtractTextPlugin(id, filename, options) {
2727
}
2828
module.exports = ExtractTextPlugin;
2929

30+
function mergeOptions(a, b) {
31+
if(!b) return a;
32+
Object.keys(b).forEach(function(key) {
33+
a[key] = b[key];
34+
});
35+
return a;
36+
};
37+
3038
ExtractTextPlugin.loader = function(options) {
3139
return require.resolve("./loader") + (options ? "?" + JSON.stringify(options) : "");
3240
};
3341

34-
ExtractTextPlugin.extract = function(before, loader) {
35-
if(loader) {
42+
ExtractTextPlugin.extract = function(before, loader, options) {
43+
if(typeof loader === "string") {
3644
return [
37-
ExtractTextPlugin.loader({omit: before.split("!").length, extract: true, remove: true}),
45+
ExtractTextPlugin.loader(mergeOptions({omit: before.split("!").length, extract: true, remove: true}, options)),
3846
before,
3947
loader
4048
].join("!");
4149
} else {
4250
loader = before;
4351
return [
44-
ExtractTextPlugin.loader({remove: true}),
52+
ExtractTextPlugin.loader(mergeOptions({remove: true}, options)),
4553
loader
4654
].join("!");
4755
}
@@ -64,17 +72,17 @@ ExtractTextPlugin.prototype.loader = function(options) {
6472
return ExtractTextPlugin.loader(options);
6573
};
6674

67-
ExtractTextPlugin.prototype.extract = function(before, loader) {
68-
if(loader) {
75+
ExtractTextPlugin.prototype.extract = function(before, loader, options) {
76+
if(typeof loader === "string") {
6977
return [
70-
this.loader({omit: before.split("!").length, extract: true, remove: true}),
78+
this.loader(mergeOptions({omit: before.split("!").length, extract: true, remove: true}, options)),
7179
before,
7280
loader
7381
].join("!");
7482
} else {
7583
loader = before;
7684
return [
77-
this.loader({remove: true}),
85+
this.loader(mergeOptions({remove: true}, options)),
7886
loader
7987
].join("!");
8088
}

loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ module.exports.pitch = function(request, preReq, data) {
3737

3838
if(query.extract !== false) {
3939
var childFilename = __dirname + " " + request;
40+
var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath
4041
var outputOptions = {
4142
filename: childFilename,
42-
publicPath: this._compilation.outputOptions.publicPath
43+
publicPath: publicPath
4344
};
4445
var childCompiler = this._compilation.createChildCompiler("extract-text-webpack-plugin", outputOptions);
4546
childCompiler.apply(new NodeTemplatePlugin(outputOptions));

0 commit comments

Comments
 (0)