Skip to content

Commit 787c607

Browse files
committed
refactor(build): refactor build
to eliminate the necessity of absolute paths
1 parent d7a9e6d commit 787c607

7 files changed

+114
-160
lines changed

build/rollup.config.vue2.js

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ if (!argv.format || argv.format === 'umd') {
120120
...baseConfig.plugins.terser
121121
})
122122
]
123+
},
124+
{
125+
file: 'dist/vue2/v-lazy-component.global.js',
126+
format: 'umd',
127+
globals,
128+
name: 'LazyComponent'
129+
},
130+
{
131+
file: 'dist/vue2/v-lazy-component.global.min.js',
132+
format: 'umd',
133+
globals,
134+
name: 'LazyComponent',
135+
plugins: [
136+
terser({
137+
...baseConfig.plugins.terser
138+
})
139+
]
123140
}
124141
],
125142
plugins: [
@@ -247,44 +264,5 @@ if (!argv.format || argv.format === 'cjs') {
247264
buildFormats.push(cjsConfig)
248265
}
249266

250-
if (!argv.format || argv.format === 'iife') {
251-
const unpkgConfig = {
252-
...baseConfig,
253-
external,
254-
output: [
255-
{
256-
file: 'dist/vue2/v-lazy-component.global.js',
257-
format: 'iife',
258-
name: 'LazyComponent',
259-
globals
260-
},
261-
{
262-
file: 'dist/vue2/v-lazy-component.global.min.js',
263-
format: 'iife',
264-
name: 'LazyComponent',
265-
globals,
266-
plugins: [
267-
terser({
268-
...baseConfig.plugins.terser
269-
})
270-
]
271-
}
272-
],
273-
plugins: [
274-
replace(baseConfig.plugins.replace),
275-
...baseConfig.plugins.preVue,
276-
css({
277-
...baseConfig.plugins.css
278-
}),
279-
vue({
280-
...baseConfig.plugins.vue
281-
}),
282-
babel(baseConfig.plugins.babel),
283-
commonjs()
284-
]
285-
}
286-
buildFormats.push(unpkgConfig)
287-
}
288-
289267
// Export config
290268
export default buildFormats

build/rollup.config.vue3.js

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ if (!argv.format || argv.format === 'umd') {
113113
...baseConfig.plugins.terser
114114
})
115115
]
116+
},
117+
{
118+
file: 'dist/vue3/v-lazy-component.global.js',
119+
format: 'umd',
120+
globals,
121+
name: 'LazyComponent'
122+
},
123+
{
124+
file: 'dist/vue3/v-lazy-component.global.min.js',
125+
format: 'umd',
126+
globals,
127+
name: 'LazyComponent',
128+
plugins: [
129+
terser({
130+
...baseConfig.plugins.terser
131+
})
132+
]
116133
}
117134
],
118135
plugins: [
@@ -249,47 +266,5 @@ if (!argv.format || argv.format === 'cjs') {
249266
buildFormats.push(cjsConfig)
250267
}
251268

252-
if (!argv.format || argv.format === 'iife') {
253-
const unpkgConfig = {
254-
...baseConfig,
255-
external,
256-
output: [
257-
{
258-
file: 'dist/vue3/v-lazy-component.global.js',
259-
format: 'iife',
260-
name: 'LazyComponent',
261-
globals
262-
},
263-
{
264-
file: 'dist/vue3/v-lazy-component.global.min.js',
265-
format: 'iife',
266-
name: 'LazyComponent',
267-
globals,
268-
plugins: [
269-
terser({
270-
...baseConfig.plugins.terser
271-
})
272-
]
273-
}
274-
],
275-
plugins: [
276-
replace(baseConfig.plugins.replace),
277-
...baseConfig.plugins.preVue,
278-
scss({
279-
...baseConfig.plugins.scss
280-
}),
281-
css({
282-
...baseConfig.plugins.css
283-
}),
284-
vue({
285-
...baseConfig.plugins.vue
286-
}),
287-
babel(baseConfig.plugins.babel),
288-
commonjs()
289-
]
290-
}
291-
buildFormats.push(unpkgConfig)
292-
}
293-
294269
// Export config
295270
export default buildFormats

dist/vue2/v-lazy-component.global.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
var LazyComponent = (function () {
2-
'use strict';
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3+
typeof define === 'function' && define.amd ? define(factory) :
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.LazyComponent = factory());
5+
})(this, (function () { 'use strict';
36

47
//
58
//
@@ -48,7 +51,7 @@ var LazyComponent = (function () {
4851
default: 0
4952
}
5053
},
51-
data: function data() {
54+
data() {
5255
return {
5356
state: {
5457
wrapperTag: this.wrapperTag,
@@ -61,18 +64,18 @@ var LazyComponent = (function () {
6164
};
6265
},
6366
watch: {
64-
isIntersected: function isIntersected(value) {
67+
isIntersected(value) {
6568
if (value) {
6669
this.state.isIntersected = true;
6770
}
6871
},
69-
'state.isIntersected': function stateIsIntersected(value) {
72+
'state.isIntersected'(value) {
7073
if (value) {
7174
this.$emit('intersected', this.$el);
7275
}
7376
}
7477
},
75-
mounted: function mounted() {
78+
mounted() {
7679
if (this.isIntersectionObserverSupported()) {
7780
if (!this.state.isIntersected && !this.state.idle) {
7881
this.observe();
@@ -84,36 +87,35 @@ var LazyComponent = (function () {
8487
this.$emit('intersected', this.$el);
8588
}
8689
},
87-
beforeDestroy: function beforeDestroy() {
90+
beforeDestroy() {
8891
if (!this.state.isIntersected && !this.state.idle) {
8992
this.unobserve();
9093
}
9194
},
9295
methods: {
93-
isIntersectionObserverSupported: function isIntersectionObserverSupported() {
96+
isIntersectionObserverSupported() {
9497
return 'IntersectionObserver' in window && 'IntersectionObserverEntry' in window && 'intersectionRatio' in window.IntersectionObserverEntry.prototype && 'isIntersecting' in window.IntersectionObserverEntry.prototype;
9598
},
96-
observe: function observe() {
97-
var _this$state = this.state,
98-
rootMargin = _this$state.rootMargin,
99-
threshold = _this$state.threshold;
100-
var config = {
99+
observe() {
100+
const {
101+
rootMargin,
102+
threshold
103+
} = this.state;
104+
const config = {
101105
root: undefined,
102-
rootMargin: rootMargin,
103-
threshold: threshold
106+
rootMargin,
107+
threshold
104108
};
105109
this.state.observer = new IntersectionObserver(this.onIntersection, config);
106110
this.state.observer.observe(this.$el);
107111
},
108-
onIntersection: function onIntersection(entries) {
109-
this.state.isIntersected = entries.some(function (entry) {
110-
return entry.intersectionRatio > 0;
111-
});
112+
onIntersection(entries) {
113+
this.state.isIntersected = entries.some(entry => entry.intersectionRatio > 0);
112114
if (this.state.isIntersected) {
113115
this.unobserve();
114116
}
115117
},
116-
unobserve: function unobserve() {
118+
unobserve() {
117119
if (this.isIntersectionObserverSupported()) {
118120
this.state.observer.unobserve(this.$el);
119121
}
@@ -197,9 +199,9 @@ var LazyComponent = (function () {
197199
}
198200

199201
/* script */
200-
var __vue_script__ = script;
202+
const __vue_script__ = script;
201203
/* template */
202-
var __vue_render__ = function __vue_render__() {
204+
var __vue_render__ = function () {
203205
var _vm = this;
204206
var _h = _vm.$createElement;
205207
var _c = _vm._self._c || _h;
@@ -218,43 +220,43 @@ var LazyComponent = (function () {
218220
var __vue_staticRenderFns__ = [];
219221

220222
/* style */
221-
var __vue_inject_styles__ = undefined;
223+
const __vue_inject_styles__ = undefined;
222224
/* scoped */
223-
var __vue_scope_id__ = undefined;
225+
const __vue_scope_id__ = undefined;
224226
/* module identifier */
225-
var __vue_module_identifier__ = undefined;
227+
const __vue_module_identifier__ = undefined;
226228
/* functional template */
227-
var __vue_is_functional_template__ = false;
229+
const __vue_is_functional_template__ = false;
228230
/* style inject */
229231

230232
/* style inject SSR */
231233

232234
/* style inject shadow dom */
233235

234-
var __vue_component__ = /*#__PURE__*/normalizeComponent({
236+
const __vue_component__ = /*#__PURE__*/normalizeComponent({
235237
render: __vue_render__,
236238
staticRenderFns: __vue_staticRenderFns__
237239
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);
238240

239241
// Import vue component
240242

241243
// install function executed by Vue.use()
242-
var install = function installLazyComponent(Vue) {
244+
const install = function installLazyComponent(Vue) {
243245
if (install.installed) return;
244246
install.installed = true;
245247
Vue.component('LazyComponent', __vue_component__);
246248
};
247249

248250
// Create module definition for Vue.use()
249-
var plugin = {
250-
install: install
251+
const plugin = {
252+
install
251253
};
252254

253255
// To auto-install on non-es builds, when vue is found
254256
// eslint-disable-next-line no-redeclare
255257
/* global window, global */
256258
{
257-
var GlobalVue = null;
259+
let GlobalVue = null;
258260
if (typeof window !== 'undefined') {
259261
GlobalVue = window.Vue;
260262
} else if (typeof global !== 'undefined') {
@@ -275,4 +277,4 @@ var LazyComponent = (function () {
275277

276278
return __vue_component__;
277279

278-
})();
280+
}));

dist/vue2/v-lazy-component.global.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)