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

Simplify Webpack configuration #324

Merged
merged 4 commits into from
Mar 24, 2017
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
modules/*/build
build
docs
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function gutenberg_register_scripts() {
wp_register_script( 'react-dom', 'https://unpkg.com/react-dom@15/dist/react-dom' . $suffix . '.js', array( 'react' ) );

// Editor
wp_register_script( 'wp-element', plugins_url( 'modules/element/build/index.js', __FILE__ ), array( 'react', 'react-dom' ) );
wp_register_script( 'wp-blocks', plugins_url( 'modules/blocks/build/index.js', __FILE__ ), array( 'wp-element' ) );
wp_register_script( 'wp-element', plugins_url( 'element/build/index.js', __FILE__ ), array( 'react', 'react-dom' ) );
wp_register_script( 'wp-blocks', plugins_url( 'blocks/build/index.js', __FILE__ ), array( 'wp-element' ) );
}
add_action( 'init', 'gutenberg_register_scripts' );

Expand All @@ -58,11 +58,11 @@ function gutenberg_scripts_and_styles( $hook ) {
if ( 'toplevel_page_gutenberg' === $hook ) {
// Scripts
wp_register_script( 'gutenberg-content', plugins_url( 'post-content.js', __FILE__ ) );
wp_enqueue_script( 'wp-editor', plugins_url( 'modules/editor/build/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'gutenberg-content' ), false, true );
wp_enqueue_script( 'wp-editor', plugins_url( 'editor/build/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'gutenberg-content' ), false, true );
wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', { content: window.content } );' );

// Styles
wp_enqueue_style( 'wp-editor', plugins_url( 'modules/editor/build/style.css', __FILE__ ) );
wp_enqueue_style( 'wp-editor', plugins_url( 'editor/build/style.css', __FILE__ ) );
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"scripts": {
"test-unit": "cross-env NODE_ENV=test webpack && mocha build --require bootstrap-test.js",
"build": "cross-env NODE_ENV=production webpack",
"lint": "eslint modules",
"lint": "eslint .",
"dev": "webpack --watch",
"test": "npm run lint && npm run test-unit"
},
Expand Down Expand Up @@ -47,6 +47,6 @@
"webpack-node-externals": "^1.5.4"
},
"dependencies": {
"hpq": "^1.1.0"
"hpq": "^1.1.1"
}
}
37 changes: 8 additions & 29 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,18 @@
*/

const glob = require( 'glob' );
const path = require( 'path' );
const webpack = require( 'webpack' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );

/**
* Base path from which modules are to be discovered.
*
* @type {String}
*/
const BASE_PATH = './modules';

/**
* Object of Webpack entry points consisting of modules discovered in the base
* path subdirectory. Treating each as an independent bundle with a shared
* configuration for library output provides a consistent authoring environment
* and exposes each separately on the global scope (window.wp.blocks, etc.).
*
* @type {Object}
*/
const entry = [ 'blocks', 'editor', 'element' ].reduce( ( memo, submodule ) => {
return Object.assign( memo, {
[ submodule ]: [ BASE_PATH, submodule, 'index.js' ].join( '/' )
} );
}, {} );

const config = {
entry: entry,
entry: {
blocks: './blocks/index.js',
editor: './editor/index.js',
element: './element/index.js'
},
output: {
filename: '[name]/build/index.js',
path: path.resolve( BASE_PATH ),
path: __dirname,
library: [ 'wp', '[name]' ],
libraryTarget: 'this'
},
Expand All @@ -48,10 +30,7 @@ const config = {
},
{
test: /\.js$/,
include: [
__dirname + '/modules',
__dirname + '/node_modules/hpq'
],
exclude: /node_modules/,
use: 'babel-loader'
},
{
Expand Down Expand Up @@ -95,7 +74,7 @@ switch ( process.env.NODE_ENV ) {

case 'test':
config.target = 'node';
config.entry = glob.sync( BASE_PATH + '/**/test/*.js' );
config.entry = glob.sync( `./{${ Object.keys( config.entry ).join() }}/test/*.js` );
config.externals = [ require( 'webpack-node-externals' )() ];
config.output = {
filename: 'build/test.js',
Expand Down