generated from Alorel/basic-library-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.proptypes.config.js
194 lines (179 loc) · 4.54 KB
/
rollup.proptypes.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import {cleanPlugin} from '@alorel/rollup-plugin-clean';
import {copyPlugin} from '@alorel/rollup-plugin-copy';
import {threadedTerserPlugin} from '@alorel/rollup-plugin-threaded-terser';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import {promises as fs} from 'fs';
import {join} from 'path';
import typescript from 'rollup-plugin-typescript2';
import * as pkgJson from './package.json';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pick = require('lodash/pick');
const distDir = join(__dirname, 'dist', 'prop-types');
const srcDir = join(__dirname, 'src');
const umdExternals = ['@alorel/preact-shadow-root'];
const external = umdExternals.concat('prop-types');
const banner$ = fs.readFile(join(__dirname, 'LICENSE'), 'utf8')
.then(f => `/*\n${f.trim()}\n*/\n`);
const baseSettings = {
external,
input: join(srcDir, 'prop-types.js'),
preserveModules: false,
watch: {
exclude: 'node_modules/*'
}
};
const baseOutput = {
assetFileNames: '[name][extname]',
banner: () => banner$,
dir: distDir,
sourcemap: false
};
const umdBaseOutput = {
...baseOutput,
format: 'umd',
globals: {
'@alorel/preact-shadow-root': 'PreactShadowRoot'
},
name: 'PreactShadowRootPropTypes'
};
const aliasConfig = {
entries: [
{find: '@alorel/preact-shadow-root', replace: join(srcDir, 'index.ts')}
]
};
const nodeResolveConfig = {
extensions: ['.js', '.ts'],
mainFields: [
'fesm5',
'esm5',
'module',
'browser',
'main'
]
};
const cjsConfig = {
include: ['node_modules/prop-types/**/*']
};
export default [
{
...baseSettings,
output: [
{
...baseOutput,
entryFileNames: 'index.js',
format: 'cjs'
},
{
...baseOutput,
entryFileNames: 'index.esm5.js',
format: 'esm'
}
],
plugins: [
cleanPlugin({dir: distDir}),
alias(aliasConfig),
nodeResolve(nodeResolveConfig),
typescript(),
commonjs(cjsConfig),
copyPlugin({
copy: ['LICENSE', 'CHANGELOG.md'],
defaultOpts: {
emitNameKind: 'fileName',
glob: {
cwd: __dirname
}
}
})
]
},
{
...baseSettings,
external: umdExternals,
output: [
{
...umdBaseOutput,
entryFileNames: 'index.umd.js'
},
{
...umdBaseOutput,
entryFileNames: 'index.umd.min.js',
plugins: [
threadedTerserPlugin({
terserOpts: {
compress: {
drop_console: true,
ecma: 5,
keep_infinity: true,
typeofs: false
},
ecma: 5,
ie8: true,
mangle: {
safari10: true
},
output: {
comments: false,
ie8: true,
safari10: true
},
safari10: true,
sourceMap: false
}
})
]
}
],
plugins: [
alias(aliasConfig),
nodeResolve(nodeResolveConfig),
typescript(),
commonjs(cjsConfig),
{
name: 'rollup-plugin-create-pkg-json',
renderStart() {
const writePkg = {
description: 'Prop types for @alorel/preact-shadow-root',
main: 'index.js',
name: '@alorel/preact-shadow-root-proptypes',
peerDependencies: {
'@alorel/preact-shadow-root': pkgJson.version,
'prop-types': '>=15.6.0'
},
...pick(pkgJson, [
'version',
'browser',
'module',
'esm5',
'jsdelivr',
'types',
'publishConfig',
'typings',
'repository',
'author',
'license'
])
};
this.emitFile({
fileName: 'package.json',
source: `${JSON.stringify(writePkg, null, 2)}\n`, // eslint-disable-line no-magic-numbers
type: 'asset'
});
this.emitFile({
fileName: 'README.md',
source: `# preact-shadow-root prop types
This should be used alongside the [main package](https://github.com/Alorel/preact-shadow-root)
`,
type: 'asset'
});
this.emitFile({
fileName: 'index.d.ts',
source: 'export {};\n',
type: 'asset'
});
}
}
]
}
];