Skip to content

Commit

Permalink
refactor(build): refactor build
Browse files Browse the repository at this point in the history
to eliminate the necessity of absolute paths
  • Loading branch information
selimdoyranli committed May 9, 2023
1 parent d7a9e6d commit 787c607
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 160 deletions.
56 changes: 17 additions & 39 deletions build/rollup.config.vue2.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ if (!argv.format || argv.format === 'umd') {
...baseConfig.plugins.terser
})
]
},
{
file: 'dist/vue2/v-lazy-component.global.js',
format: 'umd',
globals,
name: 'LazyComponent'
},
{
file: 'dist/vue2/v-lazy-component.global.min.js',
format: 'umd',
globals,
name: 'LazyComponent',
plugins: [
terser({
...baseConfig.plugins.terser
})
]
}
],
plugins: [
Expand Down Expand Up @@ -247,44 +264,5 @@ if (!argv.format || argv.format === 'cjs') {
buildFormats.push(cjsConfig)
}

if (!argv.format || argv.format === 'iife') {
const unpkgConfig = {
...baseConfig,
external,
output: [
{
file: 'dist/vue2/v-lazy-component.global.js',
format: 'iife',
name: 'LazyComponent',
globals
},
{
file: 'dist/vue2/v-lazy-component.global.min.js',
format: 'iife',
name: 'LazyComponent',
globals,
plugins: [
terser({
...baseConfig.plugins.terser
})
]
}
],
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
css({
...baseConfig.plugins.css
}),
vue({
...baseConfig.plugins.vue
}),
babel(baseConfig.plugins.babel),
commonjs()
]
}
buildFormats.push(unpkgConfig)
}

// Export config
export default buildFormats
59 changes: 17 additions & 42 deletions build/rollup.config.vue3.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ if (!argv.format || argv.format === 'umd') {
...baseConfig.plugins.terser
})
]
},
{
file: 'dist/vue3/v-lazy-component.global.js',
format: 'umd',
globals,
name: 'LazyComponent'
},
{
file: 'dist/vue3/v-lazy-component.global.min.js',
format: 'umd',
globals,
name: 'LazyComponent',
plugins: [
terser({
...baseConfig.plugins.terser
})
]
}
],
plugins: [
Expand Down Expand Up @@ -249,47 +266,5 @@ if (!argv.format || argv.format === 'cjs') {
buildFormats.push(cjsConfig)
}

if (!argv.format || argv.format === 'iife') {
const unpkgConfig = {
...baseConfig,
external,
output: [
{
file: 'dist/vue3/v-lazy-component.global.js',
format: 'iife',
name: 'LazyComponent',
globals
},
{
file: 'dist/vue3/v-lazy-component.global.min.js',
format: 'iife',
name: 'LazyComponent',
globals,
plugins: [
terser({
...baseConfig.plugins.terser
})
]
}
],
plugins: [
replace(baseConfig.plugins.replace),
...baseConfig.plugins.preVue,
scss({
...baseConfig.plugins.scss
}),
css({
...baseConfig.plugins.css
}),
vue({
...baseConfig.plugins.vue
}),
babel(baseConfig.plugins.babel),
commonjs()
]
}
buildFormats.push(unpkgConfig)
}

// Export config
export default buildFormats
66 changes: 34 additions & 32 deletions dist/vue2/v-lazy-component.global.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var LazyComponent = (function () {
'use strict';
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.LazyComponent = factory());
})(this, (function () { 'use strict';

//
//
Expand Down Expand Up @@ -48,7 +51,7 @@ var LazyComponent = (function () {
default: 0
}
},
data: function data() {
data() {
return {
state: {
wrapperTag: this.wrapperTag,
Expand All @@ -61,18 +64,18 @@ var LazyComponent = (function () {
};
},
watch: {
isIntersected: function isIntersected(value) {
isIntersected(value) {
if (value) {
this.state.isIntersected = true;
}
},
'state.isIntersected': function stateIsIntersected(value) {
'state.isIntersected'(value) {
if (value) {
this.$emit('intersected', this.$el);
}
}
},
mounted: function mounted() {
mounted() {
if (this.isIntersectionObserverSupported()) {
if (!this.state.isIntersected && !this.state.idle) {
this.observe();
Expand All @@ -84,36 +87,35 @@ var LazyComponent = (function () {
this.$emit('intersected', this.$el);
}
},
beforeDestroy: function beforeDestroy() {
beforeDestroy() {
if (!this.state.isIntersected && !this.state.idle) {
this.unobserve();
}
},
methods: {
isIntersectionObserverSupported: function isIntersectionObserverSupported() {
isIntersectionObserverSupported() {
return 'IntersectionObserver' in window && 'IntersectionObserverEntry' in window && 'intersectionRatio' in window.IntersectionObserverEntry.prototype && 'isIntersecting' in window.IntersectionObserverEntry.prototype;
},
observe: function observe() {
var _this$state = this.state,
rootMargin = _this$state.rootMargin,
threshold = _this$state.threshold;
var config = {
observe() {
const {
rootMargin,
threshold
} = this.state;
const config = {
root: undefined,
rootMargin: rootMargin,
threshold: threshold
rootMargin,
threshold
};
this.state.observer = new IntersectionObserver(this.onIntersection, config);
this.state.observer.observe(this.$el);
},
onIntersection: function onIntersection(entries) {
this.state.isIntersected = entries.some(function (entry) {
return entry.intersectionRatio > 0;
});
onIntersection(entries) {
this.state.isIntersected = entries.some(entry => entry.intersectionRatio > 0);
if (this.state.isIntersected) {
this.unobserve();
}
},
unobserve: function unobserve() {
unobserve() {
if (this.isIntersectionObserverSupported()) {
this.state.observer.unobserve(this.$el);
}
Expand Down Expand Up @@ -197,9 +199,9 @@ var LazyComponent = (function () {
}

/* script */
var __vue_script__ = script;
const __vue_script__ = script;
/* template */
var __vue_render__ = function __vue_render__() {
var __vue_render__ = function () {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
Expand All @@ -218,43 +220,43 @@ var LazyComponent = (function () {
var __vue_staticRenderFns__ = [];

/* style */
var __vue_inject_styles__ = undefined;
const __vue_inject_styles__ = undefined;
/* scoped */
var __vue_scope_id__ = undefined;
const __vue_scope_id__ = undefined;
/* module identifier */
var __vue_module_identifier__ = undefined;
const __vue_module_identifier__ = undefined;
/* functional template */
var __vue_is_functional_template__ = false;
const __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent({
const __vue_component__ = /*#__PURE__*/normalizeComponent({
render: __vue_render__,
staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);

// Import vue component

// install function executed by Vue.use()
var install = function installLazyComponent(Vue) {
const install = function installLazyComponent(Vue) {
if (install.installed) return;
install.installed = true;
Vue.component('LazyComponent', __vue_component__);
};

// Create module definition for Vue.use()
var plugin = {
install: install
const plugin = {
install
};

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

return __vue_component__;

})();
}));
2 changes: 1 addition & 1 deletion dist/vue2/v-lazy-component.global.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 787c607

Please sign in to comment.