Skip to content

Commit 073cbfe

Browse files
committed
Add rollup plugin
1 parent 766b499 commit 073cbfe

File tree

13 files changed

+1949
-1982
lines changed

13 files changed

+1949
-1982
lines changed

.browserslistrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
> 1%
2-
last 2 versions
3-
not dead
1+
current node
2+
last 2 versions and > 2%
3+
ie > 10

babel.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
const devPresets = ['@vue/babel-preset-app'];
2+
const buildPresets = ['@babel/preset-env'];
13
module.exports = {
2-
presets: [
3-
'@vue/cli-plugin-babel/preset',
4-
],
4+
presets: (process.env.NODE_ENV === 'development' ? devPresets : buildPresets),
55
};

build/rollup.config.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// rollup.config.js
2+
import fs from 'fs';
3+
import path from 'path';
4+
import vue from 'rollup-plugin-vue';
5+
import alias from '@rollup/plugin-alias';
6+
import commonjs from '@rollup/plugin-commonjs';
7+
import replace from '@rollup/plugin-replace';
8+
import babel from 'rollup-plugin-babel';
9+
import { terser } from 'rollup-plugin-terser';
10+
import minimist from 'minimist';
11+
12+
// Get browserslist config and remove ie from es build targets
13+
const esbrowserslist = fs.readFileSync('./.browserslistrc')
14+
.toString()
15+
.split('\n')
16+
.filter((entry) => entry && entry.substring(0, 2) !== 'ie');
17+
18+
const argv = minimist(process.argv.slice(2));
19+
20+
const projectRoot = path.resolve(__dirname, '..');
21+
22+
const baseConfig = {
23+
input: 'src/entry.js',
24+
plugins: {
25+
preVue: [
26+
alias({
27+
resolve: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
28+
entries: {
29+
'@': path.resolve(projectRoot, 'src'),
30+
},
31+
}),
32+
],
33+
replace: {
34+
'process.env.NODE_ENV': JSON.stringify('production'),
35+
'process.env.ES_BUILD': JSON.stringify('false'),
36+
},
37+
vue: {
38+
css: true,
39+
template: {
40+
isProduction: true,
41+
},
42+
},
43+
babel: {
44+
exclude: 'node_modules/**',
45+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
46+
},
47+
},
48+
};
49+
50+
// ESM/UMD/IIFE shared settings: externals
51+
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
52+
const external = [
53+
// list external dependencies, exactly the way it is written in the import statement.
54+
// eg. 'jquery'
55+
'vue',
56+
];
57+
58+
// UMD/IIFE shared settings: output.globals
59+
// Refer to https://rollupjs.org/guide/en#output-globals for details
60+
const globals = {
61+
// Provide global variable names to replace your external imports
62+
// eg. jquery: '$'
63+
vue: 'Vue',
64+
};
65+
66+
// Customize configs for individual targets
67+
const buildFormats = [];
68+
if (!argv.format || argv.format === 'es') {
69+
const esConfig = {
70+
...baseConfig,
71+
external,
72+
output: {
73+
file: 'dist/vue-windowing.esm.js',
74+
format: 'esm',
75+
exports: 'named',
76+
},
77+
plugins: [
78+
replace({
79+
...baseConfig.plugins.replace,
80+
'process.env.ES_BUILD': JSON.stringify('true'),
81+
}),
82+
...baseConfig.plugins.preVue,
83+
vue(baseConfig.plugins.vue),
84+
babel({
85+
...baseConfig.plugins.babel,
86+
presets: [
87+
[
88+
'@babel/preset-env',
89+
{
90+
targets: esbrowserslist,
91+
},
92+
],
93+
],
94+
}),
95+
commonjs(),
96+
],
97+
};
98+
buildFormats.push(esConfig);
99+
}
100+
101+
if (!argv.format || argv.format === 'cjs') {
102+
const umdConfig = {
103+
...baseConfig,
104+
external,
105+
output: {
106+
compact: true,
107+
file: 'dist/vue-windowing.ssr.js',
108+
format: 'cjs',
109+
name: 'VueWindowing',
110+
exports: 'named',
111+
globals,
112+
},
113+
plugins: [
114+
replace(baseConfig.plugins.replace),
115+
...baseConfig.plugins.preVue,
116+
vue({
117+
...baseConfig.plugins.vue,
118+
template: {
119+
...baseConfig.plugins.vue.template,
120+
optimizeSSR: true,
121+
},
122+
}),
123+
babel(baseConfig.plugins.babel),
124+
commonjs(),
125+
],
126+
};
127+
buildFormats.push(umdConfig);
128+
}
129+
130+
if (!argv.format || argv.format === 'iife') {
131+
const unpkgConfig = {
132+
...baseConfig,
133+
external,
134+
output: {
135+
compact: true,
136+
file: 'dist/vue-windowing.min.js',
137+
format: 'iife',
138+
name: 'VueWindowing',
139+
exports: 'named',
140+
globals,
141+
},
142+
plugins: [
143+
replace(baseConfig.plugins.replace),
144+
...baseConfig.plugins.preVue,
145+
vue(baseConfig.plugins.vue),
146+
babel(baseConfig.plugins.babel),
147+
commonjs(),
148+
terser({
149+
output: {
150+
ecma: 5,
151+
},
152+
}),
153+
],
154+
};
155+
buildFormats.push(unpkgConfig);
156+
}
157+
158+
// Export config
159+
export default buildFormats;

config/webpack.config.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

dev/serve.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue';
2+
import Dev from './serve.vue';
3+
4+
Vue.config.productionTip = false;
5+
6+
new Vue({
7+
render: (h) => h(Dev),
8+
}).$mount('#app');

dev/serve.vue

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<script>
2+
import Vue from 'vue';
3+
import ExpandingList from '@/ExpandingList';
4+
5+
export default Vue.extend({
6+
name: 'ServeDev',
7+
components: {
8+
ExpandingList,
9+
},
10+
data() {
11+
return {
12+
expandedGroup: -1,
13+
items: {
14+
number: [
15+
1,
16+
2,
17+
3,
18+
4,
19+
5,
20+
6,
21+
7,
22+
8,
23+
9,
24+
4,
25+
21,
26+
3,
27+
213,
28+
32,
29+
123,
30+
312,
31+
231,
32+
321,
33+
321,
34+
321,
35+
321,
36+
1,
37+
2,
38+
3,
39+
4,
40+
5,
41+
6,
42+
7,
43+
8,
44+
9,
45+
4,
46+
21,
47+
3,
48+
213,
49+
32,
50+
123,
51+
312,
52+
231,
53+
321,
54+
321,
55+
321,
56+
321,
57+
1,
58+
2,
59+
3,
60+
4,
61+
5,
62+
6,
63+
7,
64+
8,
65+
9,
66+
4,
67+
21,
68+
3,
69+
213,
70+
32,
71+
123,
72+
312,
73+
231,
74+
321,
75+
321,
76+
321,
77+
321,
78+
],
79+
string: [],
80+
},
81+
title: 'Take an action',
82+
};
83+
},
84+
methods: {
85+
onExpandGroup(key) {
86+
this.expandedGroup = key;
87+
88+
if (key === 'string') {
89+
this.items.string = [
90+
'ads',
91+
'add',
92+
'asasa',
93+
'dasasd',
94+
'adsadsdsa',
95+
'12asdasdsad',
96+
'ads',
97+
'add',
98+
'asasa',
99+
'dasasd',
100+
'adsadsdsa',
101+
'12asdasdsad',
102+
'ads',
103+
'add',
104+
'asasa',
105+
'dasasd',
106+
'adsadsdsa',
107+
'12asdasdsad',
108+
'ads',
109+
'add',
110+
'asasa',
111+
'dasasd',
112+
'adsadsdsa',
113+
'12asdasdsad',
114+
];
115+
}
116+
},
117+
},
118+
});
119+
</script>
120+
121+
<template>
122+
<div id="app">
123+
<ExpandingList
124+
:items="items"
125+
:expanded-item="expandedGroup"
126+
@expand="onExpandGroup">
127+
<template #group="{ item }">
128+
<span v-text="item" />
129+
</template>
130+
<template #item="{ item }">
131+
<li v-text="item" />
132+
</template>
133+
</ExpandingList>
134+
</div>
135+
</template>

dist/vue-windowing.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)