2.13.0 • Published 7 months ago

@wordpress/custom-templated-path-webpack-plugin v2.13.0

Weekly downloads
964
License
GPL-2.0-or-later
Repository
github
Last release
7 months ago

Custom Templated Path Webpack Plugin

Webpack plugin for creating custom path template tags. Extend the default set of template tags with your own custom behavior. Hooks into Webpack's compilation process to allow you to replace tags with a substitute value.

Note: This plugin targets Webpack 4.0 and newer, and is not compatible with older versions.

Usage

Construct an instance of CustomTemplatedPathPlugin in your Webpack configurations plugins entry, passing an object where keys correspond to the template tag name. The value for each key is a function passed the original intended path and data corresponding to the asset.

The following example creates a new basename tag to substitute the basename of each entry file in the build output file. When compiled, the built file will be output as build-entry.js.

const { basename } = require( 'path' );
const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );

module.exports = {
	// ...
	
	entry: './entry',

	output: {
		filename: 'build-[basename].js',
	},

	plugins: [
		new CustomTemplatedPathPlugin( {
			basename( path, data ) {
				let rawRequest;

				const entryModule = get( data, [ 'chunk', 'entryModule' ], {} );
				switch ( entryModule.type ) {
					case 'javascript/auto':
						rawRequest = entryModule.rawRequest;
						break;

					case 'javascript/esm':
						rawRequest = entryModule.rootModule.rawRequest;
						break;
				}

				if ( rawRequest ) {
					return basename( rawRequest );
				}

				return path;
			},
		} ),
	],
};

For more examples, refer to Webpack's own TemplatedPathPlugin.js, which implements the base set of template tags.

2.10.2

7 months ago

2.13.0

1 year ago

2.12.0

1 year ago

2.11.0

1 year ago

2.2.0

2 years ago

2.4.0

2 years ago

2.6.0

1 year ago

2.8.0

1 year ago

2.10.1

1 year ago

2.3.0

2 years ago

2.1.2

2 years ago

2.5.0

2 years ago

2.1.4

2 years ago

2.10.0

1 year ago

2.1.3

2 years ago

2.7.0

1 year ago

2.9.0

1 year ago

2.1.1

2 years ago

2.1.0

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0-next.0

3 years ago

2.0.0

3 years ago

1.7.0

4 years ago

1.6.1-rc.0

4 years ago

1.6.0

4 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago