This repository has been archived by the owner on Jan 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
166 lines (144 loc) · 4.06 KB
/
build.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
'use strict';
const importToUrl = require('rollup-plugin-esm-import-to-url');
const { terser } = require('rollup-plugin-terser');
const commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve');
const rollup = require('rollup');
const rimraf = require('rimraf');
const babel = require('rollup-plugin-babel');
const path = require('path');
const input = path.join(__dirname, 'assets/js/main.js');
const output = path.join(__dirname, 'public/js/');
// INPUTS
const esmPreservedInputOptions = {
input,
preserveModules: true,
onwarn: (warning, warn) => {
// Supress logging
},
plugins: [
resolve(),
commonjs(),
]
};
const iifeBundeledInputOptions = {
input,
onwarn: (warning, warn) => {
// Supress logging
},
external: ['wired-elements', 'lit-element'],
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**', // only transpile our source code
babelrc: false,
presets: [['@babel/env', { modules: false }]],
})
]
};
const iifeMinifiedInputOptions = {
input,
onwarn: (warning, warn) => {
// Supress logging
},
external: ['wired-elements', 'lit-element'],
plugins: [
resolve(),
commonjs(),
babel({
exclude: 'node_modules/**', // only transpile our source code
babelrc: false,
presets: [['@babel/env', { modules: false }]],
}),
terser(),
]
};
const esmBundeledInputOptions = {
input,
onwarn: (warning, warn) => {
// Supress logging
},
plugins: [
importToUrl({
imports: {
'wired-elements': 'https://cdn.pika.dev/wired-elements/v1',
'lit-element': 'https://cdn.pika.dev/lit-element/v2',
}
}),
resolve(),
commonjs(),
]
};
const esmMinifiedInputOptions = {
input,
onwarn: (warning, warn) => {
// Supress logging
},
plugins: [
importToUrl({
imports: {
'wired-elements': 'https://cdn.pika.dev/wired-elements/v1',
'lit-element': 'https://cdn.pika.dev/lit-element/v2',
}
}),
resolve(),
commonjs(),
terser(),
]
};
// OUTPUTS
const esmDirectoryOutputOptions = {
format: 'esm',
dir: path.join(output, '/src/'),
};
const iifeBundeledOutputOptions = {
format: 'iife',
sourcemap: true,
file: path.join(output, '/bundle.iife.js'),
name: 'PodletImage',
globals: {
'wired-elements': 'WiredElements',
'lit-element': 'LitElement',
},
};
const iifeMinifiedOutputOptions = {
format: 'iife',
sourcemap: true,
file: path.join(output, '/bundle.iife.min.js'),
name: 'PodletImage',
globals: {
'wired-elements': 'WiredElements',
'lit-element': 'LitElement',
},
};
const esmBundeledOutputOptions = {
format: 'esm',
sourcemap: true,
file: path.join(output, '/bundle.esm.js'),
};
const esmMinifiedOutputOptions = {
format: 'esm',
sourcemap: true,
file: path.join(output, '/bundle.esm.min.js'),
};
async function build() {
const preserved = await rollup.rollup(esmPreservedInputOptions);
await preserved.write(esmDirectoryOutputOptions);
console.log('src package build');
const iifeBundeled = await rollup.rollup(iifeBundeledInputOptions);
await iifeBundeled.write(iifeBundeledOutputOptions);
console.log('iife package build');
const iifeMinified = await rollup.rollup(iifeMinifiedInputOptions);
await iifeMinified.write(iifeMinifiedOutputOptions);
console.log('iife minified package build');
const esmBundeled = await rollup.rollup(esmBundeledInputOptions);
await esmBundeled.write(esmBundeledOutputOptions);
console.log('esm package build');
const esmMinified = await rollup.rollup(esmMinifiedInputOptions);
await esmMinified.write(esmMinifiedOutputOptions);
console.log('esm minified package build');
}
rimraf(output, () => {
build();
});