-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathrollup.config.mjs
118 lines (111 loc) · 2.78 KB
/
rollup.config.mjs
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
import fs from 'fs';
import { execSync } from 'child_process';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import sass from 'rollup-plugin-sass';
/**
* @returns {string} Version string like `1.58.0-dev`
*/
const getVersion = () => {
const text = fs.readFileSync('./package.json', 'utf8');
const json = JSON.parse(text);
return json.version;
}
/**
* @returns {string} Revision string like `644d08d39` (9 digits/chars).
*/
const getRevision = () => {
let revision;
try {
revision = execSync('git rev-parse --short HEAD').toString().trim();
} catch (e) {
revision = 'unknown';
}
return revision;
}
const replacements = {
values: {
'PACKAGE_VERSION': getVersion(),
'PACKAGE_REVISION': getRevision()
},
preventAssignment: true
};
const module = {
input: 'src/index.ts',
external: ['@playcanvas/observer'],
output: {
dir: `dist/module`,
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
sourcemap: true
},
plugins: [
nodeResolve(),
replace(replacements),
typescript({
noEmitOnError: true,
tsconfig: 'tsconfig.json',
sourceMap: true
})
],
treeshake: 'smallest',
cache: false
};
const react_module = {
input: 'src/index.tsx',
external: ['@playcanvas/observer', 'react', 'prop-types'],
output: {
dir: `react/dist/module`,
format: 'esm',
entryFileNames: '[name].mjs',
globals: {
'react': 'React'
},
preserveModules: true,
sourcemap: true
},
plugins: [
nodeResolve(),
replace(replacements),
typescript({
noEmitOnError: true,
tsconfig: 'react/tsconfig.json',
sourceMap: true
})
],
treeshake: 'smallest',
cache: false
};
const styles = {
input: 'src/scss/index.js',
output: {
file: 'styles/dist/index.mjs',
format: 'esm'
},
plugins: [
nodeResolve(),
sass({
insert: true,
output: false,
processor: css => postcss([autoprefixer])
.process(css, {
from: undefined
})
.then(result => result.css)
})
]
}
export default (args) => {
if (process.env.target === 'es6') {
return [module];
} else if (process.env.target === 'react:es6') {
return [react_module];
} else if (process.env.target === 'styles') {
return [styles];
}
return [module, react_module, styles];
};