Skip to content

Fix case where publicPath is a URL #34

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 3 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/replaceTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const common = require('./common.js');
const path = require('path');
const url = require('url');
const debug = common.debug;
const extractCss = common.extractCss;

Expand All @@ -19,8 +20,9 @@ const convertToPath = (cssFilename, pluginArgs, compilation) => {
? compilation.mainTemplate.getPublicPath({hash: compilation.hash})
: path.relative(path.resolve(compilation.options.output.path, path.dirname(pluginArgs.plugin.childCompilationOutputName)), compilation.options.output.path)
.split(path.sep).join('/');

if (prefix) {
cssFilename = path.join(prefix, cssFilename);
cssFilename = url.resolve(prefix, cssFilename);
}

// hash:
Expand Down
237 changes: 176 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions spec/helpers/main-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ const mainTests = (baseConfig, baseExpectations, multiEntryConfig, multiEntryExp
testPlugin(config, expected, done);
});

it('copes with a URL public path', done => {
const config = baseConfig('one_stylesheet');
config.output.publicPath = 'https://www.github.com/wibble/';
const expected = baseExpectations();
expected.html = [
/<style>[\s\S]*background: snow;[\s\S]*<\/style>/
];
testPlugin(config, expected, done);
});

it('copes with a public path with specified css file', done => {
const config = baseConfig('one_stylesheet');
config.output.publicPath = '/wibble/';
Expand All @@ -316,6 +326,21 @@ const mainTests = (baseConfig, baseExpectations, multiEntryConfig, multiEntryExp
testPlugin(config, expected, done);
});

it('copes with a URL public path with specified css file', done => {
const config = baseConfig('one_stylesheet');
config.output.publicPath = 'https://www.github.com/wibble/';
config.plugins = [
new HtmlWebpackPlugin(),
new ExtractTextPlugin('styles.css'),
new StyleExtHtmlWebpackPlugin('styles.css')
];
const expected = baseExpectations();
expected.html = [
/<style>[\s\S]*background: snow;[\s\S]*<\/style>/
];
testPlugin(config, expected, done);
});

it('understands blank options object', done => {
const config = baseConfig('one_stylesheet');
config.plugins = [
Expand Down