-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
114 lines (108 loc) · 2.97 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
// rollup index.js --file dist/webfx.js --format umd --name webfx --context this
import { terser } from "rollup-plugin-terser";
import sourcemaps from 'rollup-plugin-sourcemaps';
import resolve from '@rollup/plugin-node-resolve';
var pkgVersion = require('./package.json').version;
function transformSourcemapPath() {
return (rel, path) => {
rel = rel.replace(/\\/g, '/');
rel = rel.replace(/^\.\.\//, '');
if (rel.startsWith('node_modules')) {
var mat = rel.match(/^node_modules\/((?:@[\w\-_]+\/)?[\w\-_]+)\/(.*)$/);
if (!mat) {
console.warn(['sourcemapPathTransform', rel]);
}
var version = require(mat[1] + '/package.json').version;
return `https://cdn.jsdelivr.net/npm/${mat[1]}@${version}/${mat[2]}`;
}
return `https://github.com/lideming/webfx/raw/v${pkgVersion}/${rel}`;
};
}
function myText() {
function match(id) {
return /\.(css|svg)$/.test(id);
}
return {
name: 'my-text-loader',
transform(code, id) {
if (match(id)) {
return {
code: 'export default ' + JSON.stringify(code),
map: { mappings: '' }
};
}
}
};
}
function myVersion() {
return {
name: "version",
resolveId(src) {
if (src === './version') {
return src;
}
return null;
},
load(id) {
if (id === './version') {
return `export const version = ${JSON.stringify(require("./package.json").version)}`;
}
return null;
}
};
}
/** @type {import("rollup").RollupOptions} */
export default [{
input: 'build/index.js',
output: [
{
file: 'dist/webfx.js',
format: 'umd',
name: 'webfx'
}, {
file: 'dist/webfx.esm.js',
format: 'es',
name: 'webfx'
}, {
file: 'dist/webfx.min.js',
format: 'umd',
name: 'webfx',
sourcemap: true,
sourcemapPathTransform: transformSourcemapPath(),
plugins: [terser()]
}
],
plugins: [
sourcemaps(),
resolve(),
myVersion(),
myText(),
],
context: 'this'
}, {
input: 'build/webfxcore.js',
output: [
{
file: 'dist/webfxcore.min.js',
format: 'umd',
name: 'webfx',
sourcemap: true,
sourcemapPathTransform: transformSourcemapPath(),
plugins: [terser()]
},
{
file: 'dist/webfxcore.min.esm.js',
format: 'es',
name: 'webfx',
sourcemap: true,
sourcemapPathTransform: transformSourcemapPath(),
plugins: [terser()]
},
],
plugins: [
sourcemaps(),
resolve(),
myVersion(),
],
context: 'this'
}];