-
Notifications
You must be signed in to change notification settings - Fork 0
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
Use webpack-config with wp-scritps #6
Changes from all commits
534e9c2
f3edfc1
7277689
f115f14
faa1698
ae002fa
c94d931
a1087be
ec513c0
334dfdb
eeff79f
d27d8f4
f8d3e08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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' ); |
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": {} | ||
} |
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 ♥ .' | ||
) ); | ||
}, | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const config = require( '@wordpress/scripts/config/webpack.config.js' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next step, get rid of this file altogether :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
module.exports = Object.assign( {}, config ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 2, start using JSX in here without having to import
createElement
explicitly :)