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

Add --out-file option #745

Merged
merged 2 commits into from
Feb 14, 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
18 changes: 15 additions & 3 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,23 @@ class Asset {

generateBundleName() {
// Resolve the main file of the package.json
let main =
const main =
this.package && this.package.main
? path.resolve(path.dirname(this.package.pkgfile), this.package.main)
: null;
let ext = '.' + this.type;
const ext = '.' + this.type;

const isEntryPoint = this.name === this.options.mainFile;

// If this is the entry point of the root bundle, use outFile filename if provided
if (isEntryPoint && this.options.outFile) {
return (
path.basename(
this.options.outFile,
path.extname(this.options.outFile)
) + ext
);
}

// If this asset is main file of the package, use the sanitized package name
if (this.name === main) {
Expand All @@ -186,7 +198,7 @@ class Asset {
}

// If this is the entry point of the root bundle, use the original filename
if (this.name === this.options.mainFile) {
if (isEntryPoint) {
return path.basename(this.name, path.extname(this.name)) + ext;
}

Expand Down
1 change: 1 addition & 0 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Bundler extends EventEmitter {
const target = options.target || 'browser';
return {
outDir: Path.resolve(options.outDir || 'dist'),
outFile: options.outFile || '',
publicURL: publicURL,
watch: watch,
cache: typeof options.cache === 'boolean' ? options.cache : true,
Expand Down
14 changes: 13 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ program
'set the hostname of HMR websockets, defaults to location.hostname of current window'
)
.option('--https', 'serves files over HTTPS')
.option('-o, --open', 'automatically open in default browser')
.option('--open', 'automatically open in default browser')
.option(
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'-o, --out-file <filename>',
'set the output filename for the application entry point.'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
Expand All @@ -50,6 +54,10 @@ program
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'-o, --out-file <filename>',
'set the output filename for the application entry point.'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
Expand All @@ -71,6 +79,10 @@ program
'-d, --out-dir <path>',
'set the output directory. defaults to "dist"'
)
.option(
'-o, --out-file <filename>',
'set the output filename for the application entry point.'
)
.option(
'--public-url <url>',
'set the public URL to serve on. defaults to the same as the --out-dir option'
Expand Down
11 changes: 11 additions & 0 deletions test/asset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const assert = require('assert');
const fs = require('fs');
const Asset = require('../src/Asset');
const {bundle} = require('./utils');

describe('Asset', () => {
it('should include default implementations', async () => {
Expand All @@ -19,6 +21,15 @@ describe('Asset', () => {
assert.equal(a.generateErrorMessage(err), err);
});

it('should support overriding the filename of the root bundle', async function() {
const outFile = 'custom-out-file.html';
await bundle(__dirname + '/integration/html/index.html', {
outFile
});

assert(fs.existsSync(__dirname, `/dist/${outFile}`));
});

describe('addURLDependency', () => {
const bundleName = 'xyz';
const options = {
Expand Down