forked from sanity-io/document-internationalization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
61 lines (59 loc) · 1.7 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
const fs = require('fs')
const path = require('path')
const cleaner = require('rollup-plugin-cleaner')
const external = require('rollup-plugin-peer-deps-external')
const postcss = require('rollup-plugin-postcss')
const commonjs = require('@rollup/plugin-commonjs')
const {babel} = require('@rollup/plugin-babel')
const {nodeResolve: resolve} = require('@rollup/plugin-node-resolve')
const {ifProd} = require('./utils/env')
const srcPath = (...p) => path.resolve.apply(undefined, [__dirname, 'src', ...p].filter(Boolean))
const libPath = (...p) => path.resolve.apply(undefined, [__dirname, 'lib', ...p].filter(Boolean))
module.exports = (name) => {
const indexFile = fs.readdirSync(srcPath(name)).find((f) => f.startsWith('index.'))
return {
input: srcPath(name, indexFile),
output: [
{
dir: libPath(name),
format: 'cjs',
sourcemap: true,
},
],
plugins: [
external(),
postcss({
modules: {
camelCase: true,
generateScopedName: '[hash:base64]',
},
autoModules: false,
minimize: false,
extensions: ['.css', '.scss'],
}),
resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
babel({
exclude: '**/node_modules/**',
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelHelpers: 'runtime',
}),
commonjs({
include: 'node_modules/**',
}),
ifProd(
cleaner({
targets: [libPath(name)],
})
),
].filter(Boolean),
external: (id) =>
!!(
id.match(/@babel\/runtime/) ||
id.startsWith('config:') ||
id.startsWith('part:') ||
id.startsWith('@sanity/')
),
}
}