This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia.js
64 lines (59 loc) · 1.69 KB
/
media.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Emit images into output directory with file-loader
*
* @param {Object} [FnParams={}] Object of function parameters
* @param {Object} [FnParams.exclude] Rule exclude value
* @param {Object} [FnParams.include] Rule include value
* @param {Object} [FnParams.options] url-loader options
* @param {RegExp} [FnParams.test=/\.(gif|jpe?g|mov|mp4|png)$/i] Rule test value
* @return {Object} Module config for file-loader
*/
exports.emitMedia = ({ exclude, include, options, test } = {}) => {
if (!options) options = { name: "[name].[ext]" };
if (!test) test = /\.(gif|jpe?g|mov|mp4|png)$/i;
return {
module: {
rules: [
{
test,
exclude,
include,
use: {
loader: "file-loader",
options,
},
},
],
},
};
};
/**
* Inline images with url-loader
* If media is too large, then emit images into output directory with file-loader
*
* @param {Object} [FnParams={}] Object of function parameters
* @param {Object} [FnParams.exclude] Rule exclude value
* @param {Object} [FnParams.include] Rule include value
* @param {Object} [FnParams.options] url-loader options
* @param {RegExp} [FnParams.test=/\.(gif|jpe?g|mov|mp4|png)$/i] Rule test value
* @return {Object} Module config for url-loader
*/
exports.inlineMedia = ({ exclude, include, options, test } = {}) => {
if (!options) options = { limit: 15000, name: "[name].[ext]" };
if (!test) test = /\.(gif|jpe?g|mov|mp4|png)$/i;
return {
module: {
rules: [
{
test,
exclude,
include,
use: {
loader: "url-loader",
options,
},
},
],
},
};
};