Skip to content

Commit

Permalink
Add --out-file option (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon93s authored and devongovett committed Feb 14, 2018
1 parent c1d8d75 commit 9616277
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,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 @@ -190,7 +202,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

0 comments on commit 9616277

Please sign in to comment.