Giter VIP home page Giter VIP logo

guty-blocks-2's Introduction

Guty Blocks 2

This is designed to be a minimal, fast build environment for making WordPress Gutenberg blocks. Our priorities are to:

  1. Reduce time to development by making block generation and enqueuing fast
  2. Have a build that requires minimal enqueuing and minimal file size

To Use

  1. Clone into plugins folder of your WordPress instance
  2. Activate Guty blocks 2 in your WordPress admin
  3. In the terminal, go to the plugin folder guty-blocks-2
  4. Run npm install

npm run build will run the webpack build once.

npm run watch will run the webpack watcher and build when files are changed.

To generate a block

  1. In the terminal, go to the plugin folder guty-blocks-2
  2. Run node generate
  3. After you follow the prompts your block source files will be in assets/src/{block name}
  4. Make sure you either run npm run build or npm run watch
  5. Enjoy your block!

Deleting a block

You will need to delete the block folder and remove the import statements from index.js (and index.view.js if it included a view script).

Production build

Running npm run build:prod will build files as usual but will include js minification. A todo item for me is to include CSS minification as well.

Setup details

  • Instead of creating a php enqueuing function for each individual block, we import individual blocks into one index.js file and one style.css file.

  • Anything inside of a *.editor.css file is inlined in the block using webpack style-loader. It is never built into the dist folder, and it will not be seen on the front end view of the page. Anything in *.view.css files will be included in the single css file. This still results in the intended effect of editor styles overwriting view styles, and view styles being in both the editor and the view of the page.

  • React and ReactDOM are treated as external dependencies, meaning that they can be referenced in webpack builds, but are not actually included in the index.js build. This is so we don't duplicate React when we run the blocks. As a result file sizes for these built blocks are much smaller.

Block with view script

Sometimes there is a need to run a script on the viewing of a page. The build block with view script sets up a {blockname}.view.js file that will only be run on the front end of the site. Note that this only provides a place to run scripts that will run in the view, and the actual searching of the dom and attaching functionality is completely written by you.

Updates

July 11, 2019

  • Fixed lodash dependency issue
  • Added npm run build:prod to allow for js minification if desired

April 1, 2019

  • Removed some erroneous lines in index.js and index.view.js that were causing build errors

March 10, 2019

  • Include RichText
  • Include support for align
  • Don't include default styles ins css and don't include css className in edit or view
  • Updated readme regarding view blocks
  • Adding generate-template-files (? not sure why it wasn't installing before?)

Thanks

Thanks to Robert a.k.a codeBelt for creating generate-template-files which was a great way to set up block template generation!

guty-blocks-2's People

Contributors

dependabot[bot] avatar jimschofield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

guty-blocks-2's Issues

Minify JS

Is it possbile to add JS minification to the webpack? I tried the following:

....

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = [
    // Config for regular blocks
    {

      ....

      optimization: {
	 minimizer: [
	   new UglifyJsPlugin()
	 ]
      },

....

It does not cause any errors on build but the code build.js is not minified.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.