GithubHelp home page GithubHelp logo

webpack-assets's Introduction

webpack Asset Handling Example

Utilize webpack, @wordpress/scripts, and wp-cli to manage WordPress assets.

Available Scripts

build

Transforms your code according the configuration provided so it’s ready for production and optimized for the best performance. The output generated will be written to assets/build. This script exits after producing a single build. For incremental builds, better suited for development, see the start script.

format

It helps to enforce coding style guidelines for your files (JavaScript, YAML) by formatting source code in a consistent way.

i18n

Generates a .pot translation file.

lint:js

Helps enforce coding style guidelines for your JavaScript files.

lint:pkg-json

Helps enforce standards for your package.json files.

lint:style

Helps enforce coding style guidelines for your style files.

start

Transforms your code according the configuration provided so it’s ready for development. The script will automatically rebuild if you make changes to the code, and you will see the build errors in the console. The output generated will be writen to assets/build. For single builds, better suited for production, see the build script.

Assumptions

wp-cli

The i18n script requires wp-cli and the wp-cli/i18n-command to be available in the current environment.

WordPress < 5.0 Support

The build and start execute with --webpack-no-externals to ensure @wordpress/* packages are included within the bundle as they are not available to enqueue via wp- script handles in WordPress < 5.0.

Remove --webpack-no-externals from build and start to generate script asset files to manage @wordpress/* dependencies and exclude them from the bundle.

Style-only Entry Points

To align with current practices of separate JavaScript and CSS webpack is set up to process entry points that contain only CSS. Style-only entry point names must be prefixed with style- to ensure additional/unused .js files are not emitted for the entry point.

Single Build Directory

To help reduce complexity within webpack.config.js all emitted assets are output in a single assets/build directory.

Existing plugins should have assets managed via wp_register_script() or wp_enqueue_script() so the location of the asset can be changed freely.

Untracked Build Directory

Because build and start generate different versions of files and emit different file sets the assets/build directory is ignored and untracked. A direct clone of this repository requires users to run either npm run build or npm run start.

If asset tracking is required it is recommended to update the start script to run in production mode to reduce the likely hood of merge conflicts (which will still happen frequently with tracked assets). This can be achieved with cross-env; i.e cross-env NODE_ENV=production wp-scripts start


This project was created by (and is managed by) Sandhills Development, LLC, where we aim to craft superior experiences through ingenuity, with deep commitment to (and appreciation for) the human element.

webpack-assets's People

Contributors

spencerfinnell avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

renowncoder

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.