Skip to content

Commit

Permalink
Add mix.dump() and mix.dumpWebpackConfig();
Browse files Browse the repository at this point in the history
This is a debug command that will dump the generated Webpack config to
your console.
  • Loading branch information
JeffreyWay committed Dec 17, 2018
1 parent e08ab24 commit d14f7dc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup/webpack.mix.js
Expand Up @@ -39,6 +39,7 @@ mix.js('src/app.js', 'dist/').sass('src/app.scss', 'dist/');
// mix.webpackConfig({}); <-- Override webpack.config.js, without editing the file directly.
// mix.babelConfig({}); <-- Merge extra Babel configuration (plugins, etc.) with Mix's default.
// mix.then(function () {}) <-- Will be triggered each time Webpack finishes building.
// mix.dump(); <-- Dump the generated webpack config object t the console.
// mix.extend(name, handler) <-- Extend Mix's API with your own components.
// mix.options({
// extractVueStyles: false, // Extract .vue component styling to file, rather than inline.
Expand Down
3 changes: 2 additions & 1 deletion src/components/ComponentFactory.js
Expand Up @@ -22,7 +22,8 @@ let components = [
'Extract',
'Notifications',
'DisableNotifications',
'PurifyCss'
'PurifyCss',
'DumpWebpackConfig'
];

class ComponentFactory {
Expand Down
20 changes: 20 additions & 0 deletions src/components/DumpWebpackConfig.js
@@ -0,0 +1,20 @@
class DumpWebpackConfig {
/**
* The optional name to be used when called by Mix.
* Defaults to the class name, lowercased.
*/
name() {
return ['dumpWebpackConfig', 'dump'];
}

/**
* Register the component.
*/
register() {
Mix.listen('configReady', config => {
console.log(JSON.stringify(config, null, 2));
});
}
}

module.exports = DumpWebpackConfig;
21 changes: 21 additions & 0 deletions test/features/dumpwebpackconfig.js
@@ -0,0 +1,21 @@
import mix from './helpers/setup';

test.serial.cb('mix.dumpWebpackConfig()', t => {
let config;

console.log = webpackConfig => {
config = JSON.parse(webpackConfig);
};

mix.js(
'test/fixtures/fake-app/resources/assets/js/app.js',
'js'
).dumpWebpackConfig();

compile(t, () => {
// Quick test to ensure that a webpack config object was logged.
t.truthy(config.context);
t.true(typeof config.module === 'object');
t.true(typeof config.plugins === 'object');
});
});

0 comments on commit d14f7dc

Please sign in to comment.