Skip to content
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

Change default public-url to / #1040

Merged
merged 1 commit into from
Mar 22, 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
5 changes: 1 addition & 4 deletions src/Bundler.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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