Skip to content

Commit

Permalink
Add/wp scripts webpack (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Mar 12, 2019
1 parent 21b561b commit 4b2e531
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions wp-scripts/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "@wordpress/babel-preset-default" ],
}
1 change: 1 addition & 0 deletions wp-scripts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions wp-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## wp-scripts example plugin

WordPress plugin to showcase how to work with wp-scripts.
1 change: 1 addition & 0 deletions wp-scripts/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 wp-scripts/build/index.js.map

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

43 changes: 43 additions & 0 deletions wp-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "wp-scripts",
"version": "1.0.0",
"description": "Plugin to showcase how to work with wp-scripts.",
"author": "WordPress contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"wp-scripts"
],
"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": "wp-scripts-plugin.js",
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/plugin-transform-react-jsx": "^7.3.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@wordpress/babel-plugin-import-jsx-pragma": "file:../../gutenberg/packages/babel-plugin-import-jsx-pragma",
"@wordpress/babel-preset-default": "file:../../gutenberg/packages/babel-preset-default",
"@wordpress/browserslist-config": "file:../../gutenberg/packages/browserslist-config",
"@wordpress/scripts": "file:../../gutenberg/packages/scripts"
},
"scripts": {
"build": "wp-scripts build",
"start": "wp-scripts start",
"check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses --prod --gpl2 --ignore=abab",
"lint-js": "wp-scripts lint-js wp-scripts-plugin.js",
"lint-pkg-json": "wp-scripts lint-pkg-json package.json",
"test-e2e": "wp-scripts test-e2e",
"test-unit-js": "wp-scripts test-unit-js"
},
"dependencies": {}
}
10 changes: 10 additions & 0 deletions wp-scripts/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createElement } from '@wordpress/element';
import { registerBlockType } from '@wordpress/blocks';

registerBlockType( 'blockexample-plugin/block', {
title: 'Love',
icon: 'heart',
category: 'common',
edit: () => <p>I ♥ Gutenberg.</p>,
save: () => <p>I ♥ Gutenberg.</p>,
} );
22 changes: 22 additions & 0 deletions wp-scripts/wp-scripts-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

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

function wp_scripts_plugin_script_enqueue() {
wp_enqueue_script( 'wp-scripts-plugin-block' );
}
add_action( 'enqueue_block_editor_assets', 'wp_scripts_plugin_script_enqueue' );

0 comments on commit 4b2e531

Please sign in to comment.