forked from objectivehtml/FlipClock
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
160 lines (140 loc) · 4.14 KB
/
rollup.config.js
File metadata and controls
160 lines (140 loc) · 4.14 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import rollup from 'rollup';
import { exec } from 'child_process';
import pkg from './package.json';
import { kebabCase } from 'lodash';
import scss from 'rollup-plugin-scss';
import json from 'rollup-plugin-json';
import babel from 'rollup-plugin-babel';
import serve from 'rollup-plugin-serve';
import replace from 'rollup-plugin-replace';
import progress from 'rollup-plugin-progress';
import commonjs from 'rollup-plugin-commonjs';
import { eslint } from 'rollup-plugin-eslint';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import builtins from 'rollup-plugin-node-builtins';
import rootImport from 'rollup-plugin-root-import';
// import postcss from 'rollup-plugin-postcss';
// The type of package Rollup should create
const PACKAGE_FORMAT = 'umd';
// This is global variable used in UMD packages
const NAMESPACE = 'FlipClock';
// The directory of the package source code files
const SRC = `${__dirname}/src/`;
// The directory to ouput the compiled files
const DIST = `${__dirname}/dist/`;
// The main.js or entry point of your package
const MAINJS = `${SRC}main.js`;
// The base filename of the compiled files (no ex)
const FILENAME = kebabCase(pkg.name);
// The node_modules directory path
const NODE_MODULES = `${__dirname}/node_modules/**`;
// The options for the serve() plugin
const SERVE_OPTIONS = {
open: true,
verbose: true,
port: 10001,
contentBase: './',
host: 'localhost',
historyApiFallback: 'examples/test.html',
};
// The options for the watch plugin
const WATCH_OPTIONS = {
include: `${SRC}**`,
port: 35730
};
// The options for the livereload plugin (undefined or object).
const LIVERELOAD_OPTIONS = {
watch: DIST,
port: 35730
};
// Define the list of output globals
const OUTPUT_GLOBALS = {
// 'lodash': 'lodash'
};
// Define an array of external packages to not include in the bundle
const EXTERNAL = [
// 'lodash'
];
// Define the plugins used for the rollup process
const plugins = [
progress(),
replace({
'process.env.SERVE_OPTIONS': JSON.stringify(SERVE_OPTIONS),
'process.env.LIVERELOAD_OPTIONS': JSON.stringify(LIVERELOAD_OPTIONS),
'process.env.NODE_ENV': JSON.stringify(process.env.ROLLUP_WATCH == 'true' ? 'development' : 'production')
}),
json(),
rootImport({
// Will first look in `client/src/*` and then `common/src/*`.
root: SRC,
useEntry: 'prepend',
// If we don't find the file verbatim, try adding these extensions
extensions: ['.js']
}),
resolve({
main: true,
jsnext: true,
browser: true,
extensions: [ '.js']
}),
commonjs({
include: NODE_MODULES,
namedExports: {
}
}),
scss({
output: `${DIST}flipclock.css`
}),
babel({
exclude: NODE_MODULES
}),
globals(),
builtins(),
eslint()
];
// Add the serve/livereload plugins if watch argument has been passed
if(process.env.ROLLUP_WATCH === 'true') {
plugins.push(serve(SERVE_OPTIONS));
plugins.push(livereload(LIVERELOAD_OPTIONS));
}
// Export the config object
const config = [{
input: MAINJS,
output: {
name: NAMESPACE,
format: PACKAGE_FORMAT,
file: `${DIST}${FILENAME}.js`,
sourcemap: (process.env.ROLLUP_WATCH ? 'inline' : true),
globals: OUTPUT_GLOBALS,
},
watch: WATCH_OPTIONS,
external: EXTERNAL,
plugins: plugins
}, (process.env.NODE_ENV === 'production' ? {
input: MAINJS,
output: {
name: NAMESPACE,
format: 'es',
file: `${DIST}${FILENAME}.es.js`,
sourcemap: (process.env.ROLLUP_WATCH ? 'inline' : true),
globals: OUTPUT_GLOBALS,
},
watch: WATCH_OPTIONS,
external: EXTERNAL,
plugins: plugins
} : null)].filter(value => value !== null);
/*
const watcher = rollup.watch(config);
watcher.on('event', event => {
if(event.code === 'END') {
exec('npm run docs;', function(error, stdout, stderr) {
if (error) {
console.log(error.code);
}
});
}
});
*/
export default config;