-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
113 lines (99 loc) · 2.71 KB
/
Copy pathrollup.config.js
File metadata and controls
113 lines (99 loc) · 2.71 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
const packagesDir = path.resolve(__dirname, 'packages')
const packageDir = path.resolve(packagesDir, 'nervue')
const pkg = require(path.resolve(packageDir, `package.json`))
const name = pkg.name
const nodePlugins = [resolve(), commonjs()]
const tsPlugin = ts({
check: true,
tsconfig: path.resolve(__dirname, './tsconfig.json'),
declarationDir: `./packages/nervue/dist/${ name }.d.ts`,
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationMap: true,
},
exclude: ['packages/*/__tests__'],
},
})
const replacePlugin = replace({
preventAssignment: true,
values: {
__DEV__: false,
'process.env.NODE_ENV': '"production"'
}
})
const outputConfigs = {
mjs: {
file: `packages/nervue/${ pkg.module }`,
format: `es`,
},
cjs: {
file: `packages/nervue/${ pkg.module.replace('mjs', 'cjs') }`,
format: `cjs`,
},
global: {
file: `packages/nervue/${ pkg.unpkg }`,
format: `iife`,
},
browser: {
file: 'packages/nervue/dist/nervue.esm-browser.js',
format: `es`,
},
}
const packageBuilds = Object.keys(outputConfigs)
const packageConfigs = packageBuilds.map((format) => {
return createConfig(format, outputConfigs[format])
})
packageBuilds.forEach((buildName) => {
if (buildName === 'cjs') {
packageConfigs.push(createProductionConfig(buildName))
} else if (buildName === 'global') {
packageConfigs.push(createMinifiedConfig(buildName))
}
})
function createProductionConfig(format) {
const extension = format === 'cjs' ? 'cjs' : 'js'
const descriptor = format === 'cjs' ? '' : `.${ format }`
return createConfig(format, {
file: `packages/nervue/dist/${ name }${ descriptor }.prod.${ extension }`,
format: outputConfigs[format].format,
})
}
function createMinifiedConfig(format) {
const { terser } = require('rollup-plugin-terser')
return createConfig(
format,
{
file: `packages/nervue/dist/${ name }.${ format === 'global' ? 'iife' : format }.prod.js`,
format: outputConfigs[format].format,
},
[
terser({
module: /^esm/.test(format),
compress: {
ecma: 2015,
pure_getters: true,
},
}),
]
)
}
function createConfig(format, output, plugins = []) {
return {
input: path.join(__dirname, 'packages', 'nervue', 'src', 'index.ts'),
output,
external: ['vue-demi', 'vue', '@vue/composition-api'],
plugins: [
tsPlugin,
replacePlugin,
...nodePlugins,
...plugins
]
}
}
export default packageConfigs