-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathsiroc.config.ts
60 lines (49 loc) · 1.62 KB
/
siroc.config.ts
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
import fs from 'fs'
import { glob as _glob } from 'glob'
import pify from 'pify'
import { defineSirocConfig } from 'siroc'
import { minify, MinifyOptions } from 'terser'
const glob = pify(_glob)
let messageSent = false
export default defineSirocConfig({
sortDependencies: true,
rollup: {
externals: ['./src/app/nuxt.config.js']
},
hooks: {
// Minify build
async 'build:done'() {
// Wait for mkdist to transpile everything
await new Promise(resolve => setTimeout(resolve, 2000))
const jsFiles = [...(await glob('./dist/**/*.js')), ...(await glob('./dist/**/*.mjs'))]
const nameCache = {}
const options: MinifyOptions = {
nameCache,
ecma: 2020
}
if (!messageSent) {
const filesCount = jsFiles.length
// eslint-disable-next-line no-console
console.log(`🔐Minifying ${filesCount} built files`)
messageSent = true
}
await Promise.all(
jsFiles
// Skip plugin template file
.filter((file: string) => !['./dist/core/plugin.js', './dist/social-image/runtime/plugin.js'].includes(file))
.map(async (file: string) => {
try {
const contents = await fs.promises.readFile(file, 'utf-8')
const { code } = await minify(contents, options)
await fs.promises.writeFile(file, code || contents)
} catch (e) {
// eslint-disable-next-line no-console
console.log('Could not minify:')
// eslint-disable-next-line no-console
console.log(file)
}
})
)
}
}
})