-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.dist.js
134 lines (126 loc) · 4.04 KB
/
rollup.config.dist.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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from "@rollup/plugin-json";
import image from '@rollup/plugin-image';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import del from 'rollup-plugin-delete'
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import postcss from 'rollup-plugin-postcss';
import path from 'path';
import banner2 from 'rollup-plugin-banner2'
import { readFileSync } from 'fs';
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
const banner =
`/*!
* ${pkg.name} - v${pkg.version}
* ${pkg.homepage}
* Built: ${new Date()}
*/
`;
const globals = (id) => {
const globals = {}
if (/ol(\\|\/)/.test(id)) {
return id.replace(/\//g, '.').replace('.js', '');
} else if (id in globals) {
return globals[id];
}
return id;
}
export default function (commandOptions) {
return [{
input: 'src/ol-dji-geozones.ts',
output: [
{
file: 'dist/ol-dji-geozones.js',
format: 'umd',
name: 'DjiGeozones',
globals: globals,
sourcemap: true
},
!commandOptions.dev && {
file: 'dist/ol-dji-geozones.min.js',
format: 'umd',
plugins: [terser()],
name: 'DjiGeozones',
globals: globals,
sourcemap: true
}
],
plugins: [
banner2(() => banner),
del({ targets: 'dist/*' }),
typescript(
{
outDir: './dist',
outputToFilesystem: true,
incremental: true
}
),
json(),
resolve(),
commonjs(),
image(),
postcss({
extensions: ['.css', '.sass', '.scss'],
inject: commandOptions.dev,
extract: commandOptions.dev ? false : path.resolve('dist/ol-dji-geozones.css'),
config: {
path: './postcss.config.cjs',
ctx: {
isDev: commandOptions.dev ? true : false
}
}
}),
commandOptions.dev && serve({
open: false,
verbose: true,
contentBase: ['', 'examples'],
historyApiFallback: '/basic.html',
host: 'localhost',
port: 3000,
// execute function after server has begun listening
onListening: function (server) {
const address = server.address()
// by using a bound function, we can access options as `this`
const protocol = this.https ? 'https' : 'http'
console.log(`Server listening at ${protocol}://localhost:${address.port}/`)
}
}),
commandOptions.dev && livereload({
watch: ['src'],
delay: 500
})
],
external: function (id) {
// console.log('id', id);
return /ol\//.test(id);
}
},
...(!commandOptions.dev ?
[{
input: path.resolve('dist/ol-dji-geozones.css'),
plugins: [
postcss({
extract: true,
minimize: true,
config: {
path: './postcss.config.cjs',
ctx: {
isDev: commandOptions.dev ? true : false
}
}
}),
],
output: {
file: path.resolve('dist/ol-dji-geozones.min.css'),
},
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return
warn(warning)
}
}] : []
)
]
}