Bug fix; Add test cases

This commit is contained in:
Franklin Tse
2018-08-28 13:20:09 +08:00
parent 0739786b7f
commit 38f534ff7a
4 changed files with 113 additions and 2 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ declare namespace WebpackAssetsManifest {
fileExtRegex?: RegExp | null | false;
/** https://github.com/webdeveric/webpack-assets-manifest#sortmanifest */
sortManifest?: boolean | ((a: any, b: any) => number);
sortManifest?: boolean | ((this: WebpackAssetsManifest, a: string, b: string) => number);
/** https://github.com/webdeveric/webpack-assets-manifest#merge */
merge?: boolean | "customize";
@@ -8,6 +8,7 @@
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"esModuleInterop": true,
"baseUrl": "../",
"typeRoots": [
"../"
+8 -1
View File
@@ -1,3 +1,10 @@
{
"extends": "dtslint/dt.json"
"extends": "dtslint/dt.json",
"rules": {
"indent": [
true,
"tabs",
4
]
}
}
@@ -0,0 +1,103 @@
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;
},
});