forked from jessuni/shikwasa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
100 lines (94 loc) · 2.38 KB
/
rollup.config.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import postcss from 'rollup-plugin-postcss'
import autoprefixer from 'autoprefixer'
import replace from '@rollup/plugin-replace'
import babel from '@rollup/plugin-babel'
import cleanup from 'rollup-plugin-cleanup'
import babelMinify from 'rollup-plugin-babel-minify'
import { minify } from 'html-minifier'
import fs from 'fs'
import pkg from './package.json'
const CONSOLE_CODE = `console.log(\`%c🍊%c Shikwasa2 Podcast Player v${pkg.version} %c https://github.com/yenche123/shikwasa\`,'background-color:#00869B40;padding:4px;','background:#00869B80;color:#fff;padding:4px 0','padding: 2px 0;')`
const sharedPlugins = [
postcss({
extract: true,
plugins: [autoprefixer()],
}),
replace({
include: './src/main.js',
delimiters: ['/** ', ' */'],
'CONSOLE_MSG': CONSOLE_CODE,
preventAssignment: true,
}),
babel(),
cleanup({
comments: 'none',
}),
]
function bundle(target, format) {
let text = format
const plugins = [...sharedPlugins]
if (format === 'umd') {
text = 'min'
plugins.push(babelMinify({
comments: false,
banner: false,
sourceMap: false,
}))
}
return {
input: `src/${target}.js`,
output: {
name: target === 'main' ? 'Shikwasa' : target[0].toUpperCase() + target.slice(1),
file: `dist/shikwasa.${target === 'main' ? '' : target + '.' }${text}.js`,
format,
compact: true,
sourcemap: false,
exports: 'default',
},
plugins,
treeshake: {
moduleSideEffects: false,
},
}
}
function bundleDemo() {
const html = fs.readFileSync('./pages/public/index.html').toString()
const htmlMinified = minify(html, {
collapseWhitespace: true,
// collapseInlineTagWhitespace: true,
removeComments: true,
})
if (!fs.existsSync('./public')) {
fs.mkdirSync('./public')
}
var stream = fs.createWriteStream('./public/index.html')
stream.write(htmlMinified)
stream.end()
return {
input: 'pages/public/index.js',
output: {
dir: 'public',
compact: true,
sourcemap: false,
format: 'iife',
},
plugins: [
...sharedPlugins,
babelMinify({
comments: false,
banner: false,
sourceMap: false,
}),
],
}
}
export default () => {
if (process.env.TARGET) {
return [
bundle(process.env.TARGET, 'cjs'),
bundle(process.env.TARGET, 'umd'),
]
} else {
return bundleDemo()
}
}