Skip to content

Commit b01c175

Browse files
committed
add sfc based configuration
1 parent c15befc commit b01c175

File tree

15 files changed

+13563
-6
lines changed

15 files changed

+13563
-6
lines changed

.browserslistrc

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

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules/
3+
npm-debug.log
4+
yarn-error.log
5+
*.map
6+
.vscode

babel.config.js

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

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-onoff-toggle.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-onoff-toggle.ssr.js',
108+
format: 'cjs',
109+
name: 'VueOnoffToggle',
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-onoff-toggle.min.js',
137+
format: 'iife',
138+
name: 'VueOnoffToggle',
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;

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
import Vue from 'vue';
3+
import { OnoffToggle } from '@/entry';
4+
5+
export default Vue.extend({
6+
name: 'ServeDev',
7+
components: {
8+
OnoffToggle,
9+
}
10+
});
11+
</script>
12+
13+
<template>
14+
<div id="app">
15+
<onoff-toggle
16+
style="margin-right: 40px"
17+
onColor="#033753"
18+
:value="true"
19+
/>
20+
</div>
21+
</template>

0 commit comments

Comments
 (0)