Git Product home page Git Product logo

wp-asset-build's Introduction

build.php is a very simple command line build script designed to take groups of CSS or JS files and combine them into a built file.

What it has going for it

  • Combines files
  • Works on the command line
  • PHP!

What it doesn't

build.php does not:

  • ...Try to do smart URL rewriting by itself. You can, however, specify a list of string replacements for each bundle.
  • ...Do any kind of path error checking -- it's up to you to make sure things make sense.
  • ...Strip whitespace characters.
  • ...Strip comments.
  • ...Make you coffee.

How to use it

Each site's configuration will likely be a little different. I've found it useful to structure assets like this:

assets/
	config.php
	load.php
	asset-build/ # This repo
		config-example.php # Includes Builder.php. Defines the bundles.
		load-example.php # Includes config.php. Handles enqueueing assets/bundles into WordPress.
		build.php # Includes config.php. The command-line build script.
		lib/
			Bundler.php # This class keeps track of all the assets, bundles, and has a method to write files.
			Bundler_Loader.php

Setting up bundles is easy using the define_bundle() and add_to_bundle() methods. For example:

$bundler = new Bundler('/asset/path/prefix/');
$bundler->define('bundle_name', 'path/to/built/file.css');
$bundler->add_to('bundle_name', 'common/css/base.css');
$bundler->add_to('bundle_name', 'common/css/main.css', array('../img/', '../../../common/img/'));

At the very end, register your instance of Bundler to be built by the build script like so:

$bundler->add_to_build_profiles();

To write the files, In the command line,

$ cd /path/to/build.php

then...

$ php build.php

By default, build.php will look for your config file at ../config.php. You can specify a path to your config file like this, though:

$ php build.php --config=../path/to/config.php

That's it! Assuming PHP has write access, new files will be created for each bundle in the same directory as your old development files. Your development files will not be touched.

wp-asset-build's People

Contributors

alexkingorg avatar

Watchers

Amituddin Ali avatar

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.