Skip to content

Commit

Permalink
Change default public-url to /.
Browse files Browse the repository at this point in the history
Now that this works correctly in the dev server as of #974, this should be a much more sensible default for both production and development builds. Fixes #714.
  • Loading branch information
devongovett committed Mar 22, 2018
1 parent 43cab32 commit e24f42c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/Bundler.js
Expand Up @@ -64,10 +64,7 @@ class Bundler extends EventEmitter {
normalizeOptions(options) {
const isProduction =
options.production || process.env.NODE_ENV === 'production';
const publicURL =
options.publicUrl ||
options.publicURL ||
'/' + Path.basename(options.outDir || 'dist');
const publicURL = options.publicUrl || options.publicURL || '/';
const watch =
typeof options.watch === 'boolean' ? options.watch : !isProduction;
const target = options.target || 'browser';
Expand Down
8 changes: 4 additions & 4 deletions test/contentHashing.js
Expand Up @@ -19,7 +19,7 @@ describe('content hashing', function() {

let html = fs.readFileSync(__dirname + '/dist/index.html', 'utf8');
let filename = html.match(
/<link rel="stylesheet" href="[/\\]{1}dist[/\\]{1}(input\.[a-f0-9]+\.css)">/
/<link rel="stylesheet" href="[/\\]{1}(input\.[a-f0-9]+\.css)">/
)[1];
assert(fs.existsSync(__dirname + '/dist/' + filename));

Expand All @@ -34,7 +34,7 @@ describe('content hashing', function() {

html = fs.readFileSync(__dirname + '/dist/index.html', 'utf8');
let newFilename = html.match(
/<link rel="stylesheet" href="[/\\]{1}dist[/\\]{1}(input\.[a-f0-9]+\.css)">/
/<link rel="stylesheet" href="[/\\]{1}(input\.[a-f0-9]+\.css)">/
)[1];
assert(fs.existsSync(__dirname + '/dist/' + newFilename));

Expand All @@ -49,7 +49,7 @@ describe('content hashing', function() {
});

let js = fs.readFileSync(__dirname + '/dist/index.js', 'utf8');
let filename = js.match(/\/dist\/(test\.[0-9a-f]+\.txt)/)[1];
let filename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1];
assert(fs.existsSync(__dirname + '/dist/' + filename));

fs.writeFileSync(__dirname + '/input/test.txt', 'hello world');
Expand All @@ -59,7 +59,7 @@ describe('content hashing', function() {
});

js = fs.readFileSync(__dirname + '/dist/index.js', 'utf8');
let newFilename = js.match(/\/dist\/(test\.[0-9a-f]+\.txt)/)[1];
let newFilename = js.match(/\/(test\.[0-9a-f]+\.txt)/)[1];
assert(fs.existsSync(__dirname + '/dist/' + newFilename));

assert.notEqual(filename, newFilename);
Expand Down
10 changes: 4 additions & 6 deletions test/html.js
Expand Up @@ -142,7 +142,7 @@ describe('html', function() {

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(
/<link rel="stylesheet" href="[/\\]{1}dist[/\\]{1}html-css\.[a-f0-9]+\.css">/.test(
/<link rel="stylesheet" href="[/\\]{1}html-css\.[a-f0-9]+\.css">/.test(
html
)
);
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('html', function() {

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(
/<html>\s*<link rel="stylesheet" href="[/\\]{1}dist[/\\]{1}html-css-head\.[a-f0-9]+\.css">\s*<body>/.test(
/<html>\s*<link rel="stylesheet" href="[/\\]{1}html-css-head\.[a-f0-9]+\.css">\s*<body>/.test(
html
)
);
Expand Down Expand Up @@ -212,9 +212,7 @@ describe('html', function() {
});

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(
/<script src="[/\\]{1}dist[/\\]{1}html-css-js\.[a-f0-9]+\.js">/.test(html)
);
assert(/<script src="[/\\]{1}html-css-js\.[a-f0-9]+\.js">/.test(html));
});

it('should insert sibling bundles at correct location in tree when optional elements are absent', async function() {
Expand Down Expand Up @@ -249,7 +247,7 @@ describe('html', function() {

let html = fs.readFileSync(__dirname + '/dist/index.html');
assert(
/<\/script>\s*<link rel="stylesheet" href="[/\\]{1}dist[/\\]{1}html-css-optional-elements\.[a-f0-9]+\.css"><h1>Hello/.test(
/<\/script>\s*<link rel="stylesheet" href="[/\\]{1}html-css-optional-elements\.[a-f0-9]+\.css"><h1>Hello/.test(
html
)
);
Expand Down
4 changes: 2 additions & 2 deletions test/javascript.js
Expand Up @@ -307,8 +307,8 @@ describe('javascript', function() {

let output = run(b);
assert.equal(typeof output, 'function');
assert(/^\/dist\/test\.[0-9a-f]+\.txt$/.test(output()));
assert(fs.existsSync(__dirname + output()));
assert(/^\/test\.[0-9a-f]+\.txt$/.test(output()));
assert(fs.existsSync(__dirname + '/dist/' + output()));
});

it('should minify JS in production mode', async function() {
Expand Down
18 changes: 14 additions & 4 deletions test/server.js
Expand Up @@ -42,7 +42,7 @@ describe('server', function() {
let b = bundler(__dirname + '/integration/commonjs/index.js');
server = await b.serve(0);

let data = await get('/dist/index.js');
let data = await get('/index.js');
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.js', 'utf8'));
});

Expand All @@ -63,7 +63,7 @@ describe('server', function() {

let threw = false;
try {
await get('/dist/fake.js');
await get('/fake.js');
} catch (err) {
threw = true;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('server', function() {
let b = bundler(__dirname + '/integration/commonjs/index.js');
server = await b.serve(0, true);

let data = await get('/dist/index.js', https);
let data = await get('/index.js', https);
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.js', 'utf8'));
});

Expand All @@ -103,7 +103,17 @@ describe('server', function() {
cert: __dirname + '/integration/https/primary.crt'
});

let data = await get('/dist/index.js', https);
let data = await get('/index.js', https);
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.js', 'utf8'));
});

it('should support setting a public url', async function() {
let b = bundler(__dirname + '/integration/commonjs/index.js', {
publicUrl: '/dist'
});
server = await b.serve(0);

let data = await get('/dist/index.js');
assert.equal(data, fs.readFileSync(__dirname + '/dist/index.js', 'utf8'));
});

Expand Down
4 changes: 2 additions & 2 deletions test/typescript.js
Expand Up @@ -69,8 +69,8 @@ describe('typescript', function() {

let output = run(b);
assert.equal(typeof output.getRaw, 'function');
assert(/^\/dist\/test\.[0-9a-f]+\.txt$/.test(output.getRaw()));
assert(fs.existsSync(__dirname + output.getRaw()));
assert(/^\/test\.[0-9a-f]+\.txt$/.test(output.getRaw()));
assert(fs.existsSync(__dirname + '/dist/' + output.getRaw()));
});

it('should minify in production mode', async function() {
Expand Down

0 comments on commit e24f42c

Please sign in to comment.