front-end tooling for WordPress themes & plugins

๐Ÿ”ฅwpackio-scripts start (node)

wpack.io is a fine-tuned webpack/browser-sync configuration made specifically for WordPress Theme and Plugin Development. It gives a fine Developer Experience (DX) and a single dev dependency for all your javascript and css/sass/scss bundling requirements.

Get Started

How do I use wpack.io?

Add @wpackio/scripts to your project

Add @wpackio/scripts to your project

npx @wpackio/cli

This command will install @wpackio/scripts to your projectโ€™s devDependencies. It will also create a package.json if necessary and will add a bootstrap script to your package.json.

It provides an on-boarding experience where you donโ€™t need to worry about adding scripts and dependencies.

Bootstrap dependencies and configuration

Bootstrap dependencies and configuration

npm run bootstrap

Or, if using yarn

yarn bootstrap

This will create all the necessary files and install all additional dependencies you might need according to your project.

Configure JS entry-points

Configure JS entry-points

Now edit your newly generated wpackio.project.js file and put your javascript entry-points. An entry-point is the module which runs the final javascript code on browser. It can (and should) import other modules which has export-ed something.

webpack will automatically bundle all the dependencies together. For more information read the guide.

You can have multiple entry-point under the same entry, or have multiple file entry. More information can be found in the docs.

Consume scripts & styles with PHP

Consume scripts & styles with PHP

First install php helper library wpackio-enqueue with composer.

composer require wpackio/enqueue

We instruct it to load the files right way, using WordPress APIs like wp_enqueue_script and wp_enqueue_style.

Everything is taken care for you when you instantiate the API \WPackio\Enqueue.

Start development server

Start development server

npm start

Or if using yarn

yarn start

This will start the development server proxying your local WordPress server. Now you can have access to hot module replacement and live file watching. Just edit your files and see it live in the browser.

In the image, we see changing the heading is seen live in the browser. It is done through react-hot-loader. Do check out advanced concepts to learn how we have set that up.

Once done, press Ctrl + c to stop the server.

Build Production files

Build Production files

npm run build

Or if using yarn

yarn build

Now create production builds with this single command. By default @wpackio/scripts will optimize build, minify output and create source-maps in different files.

Create distributable zip file

Create distributable zip file

npm run archive

Or if using yarn

yarn archive

You may now want to create an installable .zip file for your theme or plugin. @wpackio/scripts makes it easy with one single command. Use it to readily deploy your plugin or theme to WordPress.org repository or to your server.

What can I do with wpack.io?

Do you always wanted to get into modern front-end development but was too worried with all the tooling involved? Well, I was too, and after spending over a year learning everything, I thought it is time WordPress has an awesome DX for front-end development too.

wpack.io is an attempt to overcome all the pain points from setting up proper tooling to make webpack work with WordPress.

  • ๐Ÿ‘‰ Have Create React App like Best In Class developer experience for WordPress Plugin/Theme development.
  • ๐Ÿ‘‰ Consume all the modern packages from npm registry.
  • ๐Ÿ‘‰ Write javascript with modern ES2018 (ES6+) syntax and compile it down to ES5 (or in accordance to your .browserslistrc).
  • ๐Ÿ‘‰ Automatically minify and bundle code with webpack.
  • ๐Ÿ‘‰ Split large files automatically and have PHP library to wp_enqueue_script all generated parts.
  • ๐Ÿ‘‰ Use SASS/SCSS language to create stylesheets.
  • ๐Ÿ‘‰ Use postcss autoprefixer to automatically make your CSS work with needed vendor prefixes.
  • ๐Ÿ‘‰ Implement all the above to your existing wamp, mamp, vvv (basically any) dev server.
  • ๐Ÿ‘‰ Create production grade, super optimized and minified files with one command (hello CI).
  • ๐Ÿ‘‰ Typescript and Flowtype to take your js carrier to the next level. This tooling itself is written in typescript.
  • ๐Ÿ‘‰ All the stuff you need to start developing using react. Hello Gutenberg!
  • ๐Ÿ‘‰ HOT MODULE REPLACEMENT(HMR) for CSS/SASS and supported javascript modules.
  • ๐Ÿ‘‰ Create directly installable .zip file.

How does wpack.io work?

Glad you asked. Behind the scene, wpack.io works on top of webpack and browser-sync.

It considers the fact that we serve files from WordPress, through wp_enqueue_* APIs and there could be multiple webpack compiled assets on the same page, coming from different plugins and themes.

Keeping it in mind and of course to provide a great DX, wpackio was made. If you would like to know more about the inner working and principles, please read the concepts.