forked from ToucanToco/weaverbird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
75 lines (72 loc) · 2.5 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import fs from 'fs';
import path from 'path';
import alias from 'rollup-plugin-alias';
import autoprefixer from "autoprefixer";
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import postcss from 'rollup-plugin-postcss'
import postcssPresetEnv from 'postcss-preset-env';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript';
import vue from 'rollup-plugin-vue';
import { terser } from 'rollup-plugin-terser';
const production = process.env.NODE_ENV === 'production' || !process.env.ROLLUP_WATCH;
/**
* small helper to get package root dir since we can't
* rely on __dirname within the rollup bundling package
* (it is fixed to the entrypoint's dir name)
*/
function packageDir() {
let currentDir = __dirname;
while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
currentDir = path.dirname(currentDir);
if (currentDir === '/') {
throw new Error('could not find package rootdir');
}
}
return currentDir;
}
export default {
input: 'src/main.ts',
output: [
{ file: 'dist/weaverbird.common.js', format: 'cjs' },
{ file: 'dist/weaverbird.esm.js', format: 'esm' },
{ file: 'dist/weaverbird.browser.js', format: 'umd', name: 'vqb' },
],
external: ['vue', 'vuex'],
plugins: [
typescript({ module: 'es2015' }),
resolve({
// Default extensions ['.mjs', '.js', '.json', '.node']
// We need to add the '.vue' extension because of the import of the component from v-calendar
// which contains relative paths without extensions.
extensions: ['.mjs', '.js', '.ts', '.json', '.node', '.vue']
}),
alias({
resolve: ['.vue', '.json'],
'@': path.join(packageDir(), '/src'),
}),
// date-fns comes from v-calendar
commonjs({ namedExports: { 'node_modules/mathjs/index.js': ['parse'], 'node_modules/date-fns/index.js': ['addDays'] } }),
// since we are using a v-calendar component directly we need to use postcss and apply the same config
postcss({
plugins: [
postcssPresetEnv({
stage: 2,
features: {
'nesting-rules': true,
},
}),
autoprefixer()
],
// extract option break CSS live reload in Storybook, comment it to get it back
extract: true,
extract: 'weaverbird.css'
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
vue({ css: false }),
json(),
production && terser(),
],
};