Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug fix. Only resolve env vars on bundling when --target=browser. (#1323
)
  • Loading branch information
emanuel-lundman authored and devongovett committed May 9, 2018
1 parent 87b1ea9 commit db07fa5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/assets/JSAsset.js
Expand Up @@ -97,7 +97,7 @@ class JSAsset extends Asset {
await babel(this);

// Inline environment variables
if (ENV_RE.test(this.contents)) {
if (this.options.target === 'browser' && ENV_RE.test(this.contents)) {
await this.parseIfNeeded();
this.traverseFast(envVisitor);
}
Expand Down
27 changes: 25 additions & 2 deletions test/javascript.js
Expand Up @@ -415,10 +415,33 @@ describe('javascript', function() {
assert.deepEqual(output(), false);
});

it('should insert environment variables', async function() {
let b = await bundle(__dirname + '/integration/env/index.js');
it('should not insert environment variables on --target=node', async function() {
let b = await bundle(__dirname + '/integration/env/index.js', {
target: 'node'
});

let output = run(b);
assert.ok(output.toString().indexOf('process.env') > -1);
assert.equal(output(), 'test:test');
});

it('should not insert environment variables on --target=electron', async function() {
let b = await bundle(__dirname + '/integration/env/index.js', {
target: 'electron'
});

let output = run(b);
assert.ok(output.toString().indexOf('process.env') > -1);
assert.equal(output(), 'test:test');
});

it('should insert environment variables on --target=browser', async function() {
let b = await bundle(__dirname + '/integration/env/index.js', {
target: 'browser'
});

let output = run(b);
assert.ok(output.toString().indexOf('process.env') === -1);
assert.equal(output(), 'test:test');
});

Expand Down

0 comments on commit db07fa5

Please sign in to comment.