Skip to content

Commit

Permalink
Use webpack-config with wp-scripts (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Feb 21, 2019
1 parent 077b606 commit 503e934
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 0 deletions.
1 change: 1 addition & 0 deletions webpack-config/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions webpack-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## webpack config example plugin

WordPress plugin to showcase how to work with webpack-config package.
126 changes: 126 additions & 0 deletions webpack-config/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webpack-config/build/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions webpack-config/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Plugin Name: Understanding Gutenberg: webpack-config
* Plugin URI: https://github.com/nosolosw/understanding-gutenberg
* Description: Plugin to showcase how to work with webpack-config.
* Version: 0.0.1
*/

function webpack_config_plugin_script_register() {
wp_register_script(
'webpack-config-plugin-block',
plugins_url( 'build/index.js', __FILE__ ),
array( 'wp-blocks', 'wp-element' )
);
}
add_action( 'init', 'webpack_config_plugin_script_register' );

function webpack_config_plugin_script_enqueue() {
wp_enqueue_script( 'webpack-config-plugin-block' );
}
add_action( 'enqueue_block_editor_assets', 'webpack_config_plugin_script_enqueue' );
29 changes: 29 additions & 0 deletions webpack-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "webpack-config",
"version": "1.0.0",
"description": "Plugin to showcase how to work with webpack-config.",
"author": "WordPress contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"webpack-config"
],
"homepage": "https://github.com/nosolosw/understanding-gutenberg#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/nosolosw/understanding-gutenberg.git"
},
"bugs": {
"url": "https://github.com/nosolosw/understanding-gutenberg/issues"
},
"main": "index.js",
"devDependencies": {
"@wordpress/scripts": "file:../../gutenberg/packages/scripts"
},
"scripts": {
"analyze": "GUTENBERG_BUNDLE_ANALYZER=true wp-scripts build",
"start": "wp-scripts start",
"build": "wp-scripts build"
},
"dependencies": {}
}
22 changes: 22 additions & 0 deletions webpack-config/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createElement } from '@wordpress/element';
import { registerBlockType } from '@wordpress/blocks';

registerBlockType( 'blockexample-plugin/block', {
title: 'Love',
icon: 'heart',
category: 'common',
edit: function() {
return ( createElement(
'p',
{},
'I ♥ Gutenberg.'
) );
},
save: function() {
return ( createElement(
'p',
{},
'I ♥ .'
) );
},
} );
3 changes: 3 additions & 0 deletions webpack-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require( '@wordpress/scripts/config/webpack.config.js' );

module.exports = Object.assign( {}, config );

0 comments on commit 503e934

Please sign in to comment.