-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
58 lines (55 loc) · 1.55 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
const copy = require('rollup-plugin-copy');
const commonjs = require('@rollup/plugin-commonjs');
const peerDepsExternal = require('rollup-plugin-peer-deps-external');
const typescript = require('@rollup/plugin-typescript');
const replace = require('@rollup/plugin-replace');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const wpGlobals = {
'react': 'React',
'@wordpress/data': 'wp.data',
'@wordpress/i18n': 'wp.i18n',
'@wordpress/components': 'wp.components',
'@wordpress/elements': 'wp.elements',
'@wordpress/hooks': 'wp.hooks',
'@wordpress/core-data': 'wp.coreData',
}
const replaceValues = {
'@@text_domain': 'lzb-entity-select',
'@@plugin_version': require('./package.json').version,
}
module.exports = {
input: './src/lzb-entity-select.tsx',
output: {
file: './dist/lzb-entity-select.js',
format: 'iife',
globals: { ...wpGlobals },
},
plugins: [
peerDepsExternal(),
nodeResolve({ preferBuiltins: false }),
commonjs(),
replace({
preventAssignment: true,
include: ['./src/*'],
delimiters: ['', ''],
values: replaceValues,
}),
copy({
targets: [{
src: 'src/*.php',
dest: 'dist/',
transform: (contents, filename) => {
let replaced = contents.toString();
Object.keys(replaceValues).forEach((value) => {
replaced = replaced.replace(new RegExp(value, 'g'), replaceValues[value]);
});
return replaced;
}
}],
}),
typescript(),
],
external: [
...Object.keys(wpGlobals)
]
}