vant/build/rollup.config.lib.js
2017-08-15 17:27:02 +08:00

66 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'fs';
import path from 'path';
import vue from 'rollup-plugin-vue';
import alias from 'zan-rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import filesize from 'rollup-plugin-filesize';
import commonjs from 'rollup-plugin-commonjs';
import componentsConfig from '../components.json';
const extensions = ['.js', '.vue'];
// 打包时排除 mixins、utils、其他组件
const utilsPath = path.resolve(__dirname, '../packages/utils/');
const mixinsPath = path.resolve(__dirname, '../packages/mixins/');
const external = [
...fs.readdirSync(utilsPath).map(item => path.resolve(utilsPath, item)),
...fs.readdirSync(mixinsPath).map(item => path.resolve(mixinsPath, item)),
...Object.keys(componentsConfig).map(component =>
path.resolve(__dirname, '../packages', component, 'index.js')
)
];
export default Object.keys(componentsConfig).map(component => {
const config = {
entry: componentsConfig[component],
targets: [
{
dest: path.resolve(__dirname, `../lib/${component}/index.js`),
format: 'cjs'
}
],
external: [
'vue',
'vue-lazyload',
path.resolve(__dirname, '../packages/mixins/popup/index.js'),
...external
],
plugins: [
vue(),
filesize(),
commonjs({
extensions
}),
resolve({
main: true,
jsnext: true,
extensions
}),
alias({
resolve: extensions,
packages: path.resolve(__dirname, '../packages')
})
]
};
// button 使用 jsx需要借助 babel
if (component === 'button') {
config.plugins.unshift(babel({
runtimeHelpers: true
}));
}
return config;
});