-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathrollup.config.js
163 lines (158 loc) · 4.59 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
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
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import globals from 'rollup-plugin-node-globals';
import postCSS from 'rollup-plugin-postcss';
import vuePlugin from 'rollup-plugin-vue';
import { terser } from 'rollup-plugin-terser';
import replace from 'rollup-plugin-replace';
import builtins from 'rollup-plugin-node-builtins';
import json from 'rollup-plugin-json';
import babel from 'rollup-plugin-babel';
import pkg from './package.json';
const minify = process.env.MINIFY;
const format = process.env.FORMAT;
const es = format === 'es';
const umd = format === 'umd';
const cjs = format === 'cjs';
let output;
let input;
const inputChunks = {
index: 'src/index.js',
version: 'src/components/Version/index.js',
install: 'src/install.js',
SearchBox: 'src/components/search/SearchBox.jsx',
ReactiveList: 'src/components/result/ReactiveList.jsx',
ResultCard: 'src/components/result/ResultCard.jsx',
ResultList: 'src/components/result/ResultList.jsx',
ReactiveBase: 'src/components/ReactiveBase/index.jsx',
SingleList: 'src/components/list/SingleList.jsx',
MultiList: 'src/components/list/MultiList.jsx',
SingleRange: 'src/components/range/SingleRange.jsx',
MultiRange: 'src/components/range/MultiRange.jsx',
RangeSlider: 'src/components/range/RangeSlider.jsx',
DynamicRangeSlider: 'src/components/range/DynamicRangeSlider.jsx',
ReactiveComponent: 'src/components/basic/ReactiveComponent.jsx',
SelectedFilters: 'src/components/basic/SelectedFilters.jsx',
SingleDropdownList: 'src/components/list/SingleDropdownList.jsx',
MultiDropdownList: 'src/components/list/MultiDropdownList.jsx',
ToggleButton: 'src/components/list/ToggleButton.jsx',
StateProvider: 'src/components/basic/StateProvider.jsx',
ReactiveGoogleMap: 'src/components/maps/ReactiveGoogleMap.jsx',
initReactivesearch: 'src/server/index.js',
RangeInput: 'src/components/range/RangeInput.jsx',
};
if (es) {
output = {
dir: 'dist/es',
format: 'es',
};
input = inputChunks;
} else if (umd) {
const globalsUMD = {
vue: 'Vue',
};
if (minify) {
output = {
file: 'dist/@appbaseio/reactivesearch-vue.umd.min.js',
format: 'umd',
globals: globalsUMD,
};
} else {
output = {
file: 'dist/@appbaseio/reactivesearch-vue.umd.js',
format: 'umd',
globals: globalsUMD,
};
}
input = 'src/index.js';
} else if (cjs) {
output = {
dir: 'dist/cjs',
format: 'cjs',
};
input = inputChunks;
} else if (format) {
throw new Error(`invalid format specified: "${format}".`);
} else {
throw new Error('no format specified. --environment FORMAT:xxx');
}
export default {
input,
output: Object.assign(
{
name: umd ? 'ReactiveSearchVue' : '@appbaseio/reactivesearch-vue',
exports: 'named',
},
output,
),
external: umd
? Object.keys(pkg.peerDependencies || {})
: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
plugins: [
json(),
vuePlugin({
preprocessStyles: true,
}),
postCSS(),
umd
? replace({
'process.env.NODE_ENV': JSON.stringify(minify ? 'production' : 'development'),
"components['vue-slider-component'] = () => import('vue-slider-component');": `
var s = document.createElement("script");
s.setAttribute("src","https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-slider-component.umd.min.js");
s.onload = function(){
var VueSlider = global['vue-slider-component'];
components['vue-slider-component'] = VueSlider;
}
document.head.appendChild(s);
`,
delimiters: ['', ''],
})
: null,
umd
? resolve({
mainFields: ['browser', 'module'],
browser: true,
preferBuiltins: false,
})
: {},
umd
? commonjs({
include: [
'../../node_modules/**',
'/node_modules/**',
/node_modules\/cross-fetch/,
/node_modules\/@appbaseio\/reactivecore/,
],
namedExports: {
'../../node_modules/highlight-words-core/dist/index.js': ['findAll'],
},
})
: {},
babel({
...(!umd && { exclude: 'node_modules/**' }),
babelrc: false,
extensions: ['.js', '.jsx', '.ts'],
presets: [
[
'@babel/preset-env',
{
loose: true,
modules: false,
},
],
],
plugins: [
['@vue/babel-plugin-jsx', { transformOn: true, mergeProps: true }],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-proposal-json-strings',
],
}),
umd ? globals() : {},
umd ? builtins() : {},
minify ? terser() : null,
].filter(Boolean),
};