-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
110 lines (94 loc) · 2.87 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
100
101
102
103
104
105
106
107
108
109
110
import path from 'path'
import ts from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
const pkg = require('./package.json')
const name = pkg.name
const banner = `/*!
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} Aaron Lam
* @license MIT
*/`
// ensure TS checks only once for each build
let hasTSChecked = false
const outputConfigs = {
// each file name has the format: `dist/${name}.${format}.js`
cjs: {
file: pkg.main,
format: `cjs`
},
global: {
file: `dist/${name}.global.js`,
format: `iife`
},
'esm-bundler': {
file: `dist/${name}.esm-bundler.js`,
format: `es`
},
'esm-browser': {
file: `dist/${name}.esm-browser.js`,
format: `es`
}
}
const packageFormats = Object.keys(outputConfigs)
const packageConfigs = packageFormats.map(format =>
createConfig(format, outputConfigs[format])
)
// only add the production ready if we are bundling the options
packageFormats.forEach(format => {
if (format === 'cjs') {
packageConfigs.push(createProductionConfig(format))
}
})
console.log(packageConfigs)
export default packageConfigs
function createConfig(format, output, plugins = []) {
if (!output) {
console.log(require('chalk').yellow(`invalid format: "${format}"`))
process.exit(1)
}
output.sourcemap = false
output.banner = banner
output.externalLiveBindings = false
output.globals = {
vue: 'Vue'
}
const isGlobalBuild = format === 'global'
if (isGlobalBuild) {
output.name = 'VueNextI18n'
}
const shouldEmitDeclarations = !hasTSChecked
const tsPlugin = ts({
check: !hasTSChecked,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
sourceMap: output.sourcemap,
declaration: shouldEmitDeclarations,
declarationMap: shouldEmitDeclarations
},
exclude: ['__tests__', 'test-dts']
}
})
// we only need to check TS and generate declarations once for each build.
// it also seems to run into weird issues when checking multiple times
// during a single build.
hasTSChecked = true
const external = ['vue']
const nodePlugins = [resolve(), commonjs()]
return {
input: `src/index.ts`,
// Global and Browser ESM builds inlines everything so that they can be
// used alone.
external,
plugins: [tsPlugin, ...nodePlugins, ...plugins],
output
}
}
function createProductionConfig(format) {
return createConfig(format, {
file: `dist/${name}.${format}.prod.js`,
format: outputConfigs[format].format
})
}