1 | let processImport = require('size-limit/process-import')
|
2 |
|
3 | function escapeRegexp(string) {
|
4 | return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
|
5 | }
|
6 |
|
7 | const STATIC =
|
8 | /\.(eot|woff2?|ttf|otf|svg|png|jpe?g|gif|webp|mp4|mp3|ogg|pdf|html|ico|md)$/
|
9 |
|
10 | module.exports = async function getConfig(limitConfig, check, output) {
|
11 | await processImport(check, output)
|
12 |
|
13 | if (check.files.length === 0) {
|
14 | check.missed = true
|
15 | check.webpack = false
|
16 | }
|
17 |
|
18 | let config = {
|
19 | entry: {
|
20 | index: check.files
|
21 | },
|
22 | output: {
|
23 | filename: limitConfig.why && `${limitConfig.project}.js`,
|
24 | path: output
|
25 | },
|
26 | optimization: {
|
27 | concatenateModules: !check.disableModuleConcatenation
|
28 | },
|
29 | module: {
|
30 | rules: [
|
31 | {
|
32 | test: STATIC,
|
33 | type: 'asset/resource'
|
34 | }
|
35 | ]
|
36 | }
|
37 | }
|
38 |
|
39 | if (check.ignore && check.ignore.length > 0) {
|
40 | let escaped = check.ignore.map(i => escapeRegexp(i))
|
41 | let ignorePattern = new RegExp(`^(${escaped.join('|')})($|/)`)
|
42 | config.externals = ({ request }, callback) => {
|
43 | if (ignorePattern.test(request)) {
|
44 | callback(null, 'root a')
|
45 | } else {
|
46 | callback()
|
47 | }
|
48 | }
|
49 | }
|
50 |
|
51 | if (!config.plugins) config.plugins = []
|
52 |
|
53 | return config
|
54 | }
|