Merge pull request #28440 from FranklinWhale/webpack-assets-manifest

Definition of webpack-assets-manifest
This commit is contained in:
Armando Aguirre
2018-08-30 10:38:14 -07:00
committed by GitHub
4 changed files with 287 additions and 0 deletions
+147
View File
@@ -0,0 +1,147 @@
// Type definitions for webpack-assets-manifest 3.0
// Project: https://github.com/webdeveric/webpack-assets-manifest
// Definitions by: Franklin Tse <https://github.com/FranklinWhale>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
import { Plugin } from "webpack";
import { SyncHook, SyncWaterfallHook } from "tapable";
declare class WebpackAssetsManifest extends Plugin {
constructor(options?: WebpackAssetsManifest.Options);
/** https://github.com/webdeveric/webpack-assets-manifest#hooks */
hooks: {
apply: SyncHook<WebpackAssetsManifest>;
/**
* The `SyncWaterfallHook` class supports 3 type parameters only but this hook actually has 4 parameters. The type of 4th parameter is `AnyObject`.
*
* Refer to https://github.com/webdeveric/webpack-assets-manifest#hooks for details
*/
customize: SyncWaterfallHook<WebpackAssetsManifest.Entry, WebpackAssetsManifest.AnyObject, WebpackAssetsManifest>;
transform: SyncWaterfallHook<WebpackAssetsManifest.AnyObject, WebpackAssetsManifest>;
done: SyncHook<WebpackAssetsManifest, WebpackAssetsManifest.AnyObject>;
options: SyncWaterfallHook<WebpackAssetsManifest.Options>;
afterOptions: SyncHook<WebpackAssetsManifest.Options>;
};
/** https://github.com/webdeveric/webpack-assets-manifest#options-read-the-schema */
options: WebpackAssetsManifest.Options;
/** https://github.com/webdeveric/webpack-assets-manifest#options-read-the-schema */
defaultOptions: WebpackAssetsManifest.Options;
/** Determine if the manifest data is currently being merged */
isMerging: boolean;
/** Get the file extension */
getExtension(filename: string): string;
/** Replace backslash with forward slash */
fixKey(key: string): string;
/** Determine if the filename matches the HMR filename pattern */
isHMR(filename: string): boolean;
/** Add item to assets without modifying the key or value */
setRaw(key: string, value: string): this;
/** Add an item to the manifest */
set(key: string, value: string): this;
/** Determine if an item exist in the manifest */
has(key: string): boolean;
/** Get an item from the manifest */
get(key: string, defaultValue?: string): any;
/** Delete an item from the manifest */
delete(key: string): boolean;
/** Get the file system path to the manifest */
getOutputPath(): string;
/** Get the public path for the filename */
getPublicPath(filename: string): string;
/**
* Get a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler) for the manifest
*
* @param raw - Use `setRaw` instead of `set`
*/
getProxy(raw?: boolean): ProxyHandler<WebpackAssetsManifest>;
}
declare namespace WebpackAssetsManifest {
interface Options {
/** https://github.com/webdeveric/webpack-assets-manifest#assets */
assets?: object;
/** https://github.com/webdeveric/webpack-assets-manifest#output */
output?: string;
/** https://github.com/webdeveric/webpack-assets-manifest#replacer */
replacer?: null | ReadonlyArray<string> | ((key: string, value: string) => number | string | boolean | null | object | undefined);
/** https://github.com/webdeveric/webpack-assets-manifest#space */
space?: number;
/** https://github.com/webdeveric/webpack-assets-manifest#writetodisk */
writeToDisk?: boolean;
/** https://github.com/webdeveric/webpack-assets-manifest#fileextregex */
fileExtRegex?: RegExp | null | false;
/** https://github.com/webdeveric/webpack-assets-manifest#sortmanifest */
sortManifest?: boolean | ((this: WebpackAssetsManifest, a: string, b: string) => number);
/** https://github.com/webdeveric/webpack-assets-manifest#merge */
merge?: boolean | "customize";
/** https://github.com/webdeveric/webpack-assets-manifest#publicpath */
publicPath?: string | boolean | null | (((filename: string, manifest: WebpackAssetsManifest) => string));
/** https://github.com/webdeveric/webpack-assets-manifest#apply */
apply?: ((manifest: WebpackAssetsManifest) => void) | null;
/** https://github.com/webdeveric/webpack-assets-manifest#customize */
customize?: ((entry: Entry, original: AnyObject, manifest: WebpackAssetsManifest, asset: AnyObject) => Entry | false) | null;
/** https://github.com/webdeveric/webpack-assets-manifest#transform */
transform?: ((assets: AnyObject, manifest: WebpackAssetsManifest) => any) | null;
/** https://github.com/webdeveric/webpack-assets-manifest#done */
done?: ((manifest: WebpackAssetsManifest, stats: AnyObject) => void) | null;
/** https://github.com/webdeveric/webpack-assets-manifest#entrypoints */
entrypoints?: boolean;
/** https://github.com/webdeveric/webpack-assets-manifest#entrypointskey */
entrypointsKey?: string | false;
/** https://github.com/webdeveric/webpack-assets-manifest#integrity */
integrity?: boolean;
/** https://github.com/webdeveric/webpack-assets-manifest#integrityhashes */
integrityHashes?: ReadonlyArray<string>;
/** https://github.com/webdeveric/webpack-assets-manifest#integritypropertyname */
integrityPropertyName?: string;
}
interface Entry {
key: string;
value: string;
}
interface AnyObject extends Object {
[index: string]: any;
}
}
export = WebpackAssetsManifest;
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"esModuleInterop": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"webpack-assets-manifest-tests.ts"
]
}
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"indent": [
true,
"tabs",
4
]
}
}
@@ -0,0 +1,106 @@
import WebpackAssetsManifest from "webpack-assets-manifest";
/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/asset-integrity.js */
new WebpackAssetsManifest({
output: 'asset-integrity-manifest.json',
integrity: true,
publicPath: true,
customize(entry, original, manifest, asset) {
return {
key: entry.value,
value: asset && asset.integrity,
};
},
});
/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/aws-s3-data-integrity.js */
new WebpackAssetsManifest({
output: 'aws-s3-data-integrity-manifest.json',
integrity: true,
integrityHashes: ['md5'],
integrityPropertyName: 'md5',
publicPath: 's3://some-bucket/some-folder/',
customize(entry, original, manifest, asset) {
return {
key: entry.value,
value: asset && asset.md5.substr(4),
};
},
});
/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/custom-cdn.js */
new WebpackAssetsManifest({
output: 'custom-cdn-manifest.json',
publicPath(filename, manifest) {
switch (manifest.getExtension(filename).substr(1).toLowerCase()) {
case 'jpg': case 'jpeg': case 'gif': case 'png': case 'svg':
return `https://img.cdn.example.com/${filename}`;
case 'css':
return `https://css.cdn.example.com/${filename}`;
case 'js':
return `https://js.cdn.example.com/${filename}`;
default:
return `https://cdn.example.com/${filename}`;
}
},
});
/**
* https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/customized.js
* https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/merged.js
*/
new WebpackAssetsManifest({
output: 'customized-manifest.json',
merge: true,
customize(entry, original, manifest, asset) {
if (manifest.isMerging) {}
if (entry.key.toLowerCase().endsWith('.map')) {
return false;
}
return {
key: `src/${entry.key}`,
value: `dist/${entry.value}`,
};
},
});
/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/sorted.js */
new WebpackAssetsManifest({
output: 'sorted-manifest.json',
sortManifest(a, b) {
const extA = this.getExtension(a);
const extB = this.getExtension(b);
if (extA > extB) {
return 1;
}
if (extA < extB) {
return -1;
}
return a.localeCompare(b);
},
});
/** https://github.com/webdeveric/webpack-assets-manifest/blob/master/examples/transformed.js */
new WebpackAssetsManifest({
output: 'transformed-manifest.json',
transform(assets, manifest) {
const { name, version } = require('./package.json');
assets.package = {
name,
version,
};
const { key, value } = manifest.hooks.customize.call({
key: 'YourKey',
value: 'YourValue',
});
assets[key] = value;
},
});