-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.dist.js
191 lines (186 loc) · 7 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import svg from 'rollup-plugin-svg-import';
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 = {
'jspdf': 'jsPDF',
'modal-vanilla': 'Modal',
'events': 'EventEmitter',
'pdfjs-dist': 'pdfjsLib'
};
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/index-umd.ts',
output: [
{
file: 'dist/ol-pdf-printer.js',
format: 'umd',
name: 'PdfPrinter',
globals: globals,
intro: 'var global = window;',
sourcemap: true
},
!commandOptions.dev && {
intro: 'var global = window;',
file: 'dist/ol-pdf-printer.min.js',
format: 'umd',
plugins: [terser()],
name: 'PdfPrinter',
globals: globals,
sourcemap: true
}
],
plugins: [
banner2(() => banner),
del({ targets: 'dist/*' }),
resolve({ browser: true }),
typescript({
outDir: 'dist',
outputToFilesystem: true,
declarationMap: true,
incremental: false
}),
nodePolyfills(), // Events
commonjs(),
svg(),
postcss({
include: 'src/assets/scss/-ol-pdf-printer.bootstrap5.scss',
extensions: ['.css', '.sass', '.scss'],
inject: commandOptions.dev,
extract: commandOptions.dev
? false
: path.resolve(
'dist/css/ol-pdf-printer.bootstrap5.css'
),
config: {
path: './postcss.config.cjs',
ctx: {
isDev: commandOptions.dev ? true : false
}
}
}),
postcss({
include: 'src/assets/scss/ol-pdf-printer.scss',
extensions: ['.css', '.sass', '.scss'],
inject: commandOptions.dev ? true : false,
extract: commandOptions.dev
? false
: path.resolve('dist/css/ol-pdf-printer.css'),
sourceMap: commandOptions.dev ? true : false,
minimize: false,
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: 3007,
// 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: ['dist'],
delay: 500
})
],
external: (id) => {
return /(?!ol\/TileState)(^ol|jspdf|pdfjs-dist(\\|\/))/.test(
id
);
}
},
...(!commandOptions.dev
? [
{
input: path.resolve('dist/css/ol-pdf-printer.css'),
plugins: [
postcss({
extract: true,
minimize: true,
config: {
path: './postcss.config.cjs',
ctx: {
isDev: commandOptions.dev ? true : false
}
}
})
],
output: {
file: path.resolve('dist/css/ol-pdf-printer.min.css')
},
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return;
warn(warning);
}
},
{
input: path.resolve(
'dist/css/ol-pdf-printer.bootstrap5.css'
),
plugins: [
postcss({
extract: true,
minimize: true,
config: {
path: './postcss.config.cjs',
ctx: {
isDev: commandOptions.dev ? true : false
}
}
})
],
output: {
file: path.resolve(
'dist/css/ol-pdf-printer.bootstrap5.min.css'
)
},
onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return;
warn(warning);
}
}
]
: [])
];
}