Skip to content
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
6 changes: 4 additions & 2 deletions bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ if (runtimeConfig.useDevServer) {

return require('webpack-dev-server/bin/webpack-dev-server');
} else {
console.log('Running webpack ...');
console.log();
if (!runtimeConfig.outputJson) {
console.log('Running webpack ...');
console.log();
}

return require('webpack/bin/webpack');
}
Expand Down
52 changes: 30 additions & 22 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ class ConfigGenerator {

notifierPluginUtil(plugins, this.webpackConfig);

const friendlyErrorPlugin = friendlyErrorPluginUtil(this.webpackConfig);
plugins.push({
plugin: friendlyErrorPlugin,
priority: PluginPriorities.FriendlyErrorsWebpackPlugin
});
if (!this.webpackConfig.runtimeConfig.outputJson) {
const friendlyErrorPlugin = friendlyErrorPluginUtil(this.webpackConfig);
plugins.push({
plugin: friendlyErrorPlugin,
priority: PluginPriorities.FriendlyErrorsWebpackPlugin
});

assetOutputDisplay(plugins, this.webpackConfig, friendlyErrorPlugin);
assetOutputDisplay(plugins, this.webpackConfig, friendlyErrorPlugin);
}

this.webpackConfig.plugins.forEach(function(plugin) {
plugins.push(plugin);
Expand All @@ -274,22 +276,28 @@ class ConfigGenerator {
buildStatsConfig() {
// try to silence as much as possible: the output is rarely helpful
// this still doesn't remove all output
return {
hash: false,
version: false,
timings: false,
assets: false,
chunks: false,
maxModules: 0,
modules: false,
reasons: false,
children: false,
source: false,
errors: false,
errorDetails: false,
warnings: false,
publicPath: false,
};
let stats = {};

if (!this.webpackConfig.runtimeConfig.outputJson) {
stats = {
hash: false,
version: false,
timings: false,
assets: false,
chunks: false,
maxModules: 0,
modules: false,
reasons: false,
children: false,
source: false,
errors: false,
errorDetails: false,
warnings: false,
publicPath: false,
};
}

return stats;
}

buildDevServerConfig() {
Expand Down
5 changes: 5 additions & 0 deletions lib/config/parse-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function(argv, cwd) {
runtimeConfig.command = argv._[0];
runtimeConfig.useDevServer = false;
runtimeConfig.useHotModuleReplacement = false;
runtimeConfig.outputJson = false;

switch (runtimeConfig.command) {
case 'dev':
Expand Down Expand Up @@ -68,6 +69,10 @@ module.exports = function(argv, cwd) {
runtimeConfig.helpRequested = true;
}

if (argv.j || argv.json) {
runtimeConfig.outputJson = true;
}

runtimeConfig.babelRcFileExists = (typeof resolveRc(require('fs'), runtimeConfig.context)) !== 'undefined';

return runtimeConfig;
Expand Down
35 changes: 35 additions & 0 deletions test/bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const chai = require('chai');
chai.use(require('chai-fs'));
const expect = chai.expect;
const path = require('path');
const testSetup = require('../../lib/test/setup');
const fs = require('fs-extra');
Expand Down Expand Up @@ -88,4 +89,38 @@ export default config;
done();
});
});

it('Smoke test using the --json option', (done) => {
testSetup.emptyTmpDir();
const testDir = testSetup.createTestAppDir();

fs.writeFileSync(
path.join(testDir, 'webpack.config.js'),
`
const Encore = require('../../index.js');
Encore
.setOutputPath('build/')
.setPublicPath('/build')
.addEntry('main', './js/no_require')
;

module.exports = Encore.getWebpackConfig();
`
);

const binPath = path.resolve(__dirname, '../', '../', 'bin', 'encore.js');
exec(`node ${binPath} dev --json --context=${testDir}`, { cwd: testDir }, (err, stdout, stderr) => {
if (err) {
throw new Error(`Error executing encore: ${err} ${stderr} ${stdout}`);
}

const parsedOutput = JSON.parse(stdout);

expect(parsedOutput).to.be.an('object');
expect(parsedOutput.modules).to.be.an('array');
expect(parsedOutput.modules.length).to.equal(1);

done();
});
});
});