forked from FormidableLabs/prism-react-renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
141 lines (129 loc) · 3.2 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
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
import * as globby from 'globby';
import * as path from 'path';
import * as fs from 'fs';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import buble from '@rollup/plugin-buble';
import babel from '@rollup/plugin-babel';
const pkg = require('./package.json');
const externalModules = [
'dns',
'fs',
'path',
'url',
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
];
const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
const bundlePredicate = /\/themes\//;
const externalTest = id => externalPredicate.test(id) || bundlePredicate.test(id);
const config = {
onwarn: () => {},
treeshake: { propertyReadSideEffects: false },
external: externalTest,
plugins: [
resolve({
dedupe: externalModules,
mainFields: ['module', 'jsnext', 'main'],
preferBuiltins: false,
browser: true,
}),
commonjs({
ignoreGlobal: true,
include: /\/node_modules\//,
namedExports: {
react: Object.keys(require('react')),
},
}),
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [],
plugins: [
'babel-plugin-macros',
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-proposal-class-properties'
],
}),
buble({
transforms: {
unicodeRegExp: false,
dangerousForOf: true,
dangerousTaggedTemplateString: true,
},
objectAssign: 'Object.assign',
exclude: 'node_modules/**',
}),
babel({
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [],
plugins: [
'@babel/plugin-transform-object-assign',
['@babel/plugin-transform-react-jsx', {
pragma: 'React.createElement',
pragmaFrag: 'React.Fragment',
useBuiltIns: true
}],
],
})
]
};
if (!fs.existsSync('themes/')) fs.mkdirSync('themes');
const themes = globby.sync('src/themes/*.js').map(input => {
const name = path.basename(input, '.js');
const dir = 'themes/' + name;
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
const packageJson = {
name: '@prism-react-renderer/' + name,
private: true,
sideEffects: false,
main: 'index.cjs.js',
module: 'index.js',
license: 'MIT'
};
fs.writeFileSync(
path.join('./themes', name, 'package.json'),
JSON.stringify(packageJson, undefined, 2)
);
return {
...config,
input,
output: [
{
file: path.join('./themes', name, 'index.cjs.js'),
format: 'cjs'
},
{
file: path.join('./themes', name, 'index.js'),
format: 'esm'
}
]
};
});
export default [
{
...config,
input: {
dist: './src/index.js',
prism: './src/vendor/prism/index.js',
},
output: [
{
dir: './',
entryFileNames: '[name]/index.cjs.js',
chunkFileNames: 'dist/[name]-[hash].cjs.js',
format: 'cjs'
},
{
dir: './',
entryFileNames: '[name]/index.js',
chunkFileNames: 'dist/[name]-[hash].js',
format: 'esm'
}
]
},
...themes
];