-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
145 lines (135 loc) · 4.02 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
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
/* eslint-disable no-undef */
const path = require("path");
//import babel from "rollup-plugin-babel";
import {eslint} from "rollup-plugin-eslint";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import {terser} from "rollup-plugin-terser";
import sass from "rollup-plugin-sass";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
import json from "rollup-plugin-json";
import visualizer from "rollup-plugin-visualizer";
import trash from "rollup-plugin-delete";
import copy from "rollup-plugin-copy";
import pug from 'rollup-plugin-pug';
import url from 'rollup-plugin-url';
import {plugin as globImport} from 'rollup-plugin-glob-import';
import * as meta from "./package.json";
const pugEmitAssets = (plugin) => {
const pluginTransform = plugin.transform;
plugin.transform = function(code, id) {
const result = pluginTransform(code, id);
if (result !== null) {
const name = /\/([\w\.-]+)\.pug$/;
this.emitFile({
type: 'asset',
source: JSON.parse(result.code.slice(15, -2)),
fileName: name.exec(id)[1] + ".html"
})
result.dependencies && result.dependencies.forEach(this.addWatchFile);
return {
code: "export default 'default'",
map: null
};
}
return;
}
return plugin;
}
const jsonEmitAssets = (plugin) => {
const pluginTransform = plugin.transform;
plugin.transform = function(code, id) {
const result = pluginTransform(code, id);
if (result !== null) {
const name = /\/([\w\.-]+)\.json$/;
this.emitFile({
type: 'asset',
source: "var VIZABI_MODEL = " + result.code.slice(15),
fileName: "assets/js/toolconfigs/" + name.exec(id)[1] + ".js"
})
result.dependencies && result.dependencies.forEach(this.addWatchFile);
return {
code: "export default 'default'",
map: null
};
}
return;
}
return plugin;
}
const copyright = `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`;
const __PROD__ = process.env.NODE_ENV === 'production';
const preview = {
input: {"preview":"src/index.js"},
output: {
name: "preview",
dir: "build",
format: "umd",
banner: copyright,
sourcemap: true
},
plugins: [
(process.env.NODE_ENV === "production" && trash({
targets: ['build/*', '!build/vizabi*/**']
})),
copy({
targets: [
{ src: "src/assets/js", dest: "build/assets" },
{ src: "src/data", dest: "build" },
],
verbose: true
}),
resolve(),
commonjs(),
globImport({
format: 'import'
}),
//(process.env.NODE_ENV === "production" && eslint()),
// babel({
// exclude: "node_modules/**"
// }),
pugEmitAssets(pug({
doctype: 'js',
pretty: true,
staticPattern: /\S/
})),
jsonEmitAssets(json({
namedExports:false,
indent: ' '
})),
url({
limit: 0,
fileName: "vendor/[dirname][name][extname]",
include: [
"**/*.css",
/\.(otf|eot|svg|ttf|woff2?)$/,
],
destDir: "build/assets"
}),
url({
limit: 0,
fileName: "vendor/js/[name]/[name][extname]",
include: [
/(d3|mobx\.umd|web|reader)\.js$/,
],
destDir: "build/assets"
}),
sass({
output: "build/assets/css/main.css",
}),
replace({
ENV: JSON.stringify(process.env.NODE_ENV || "development")
}),
(process.env.NODE_ENV === "production" && terser({output: {preamble: copyright}})),
(process.env.NODE_ENV === "devserver" && serve("build")),
(process.env.NODE_ENV === "devserver" && livereload("build")),
visualizer({
filename: "./build/stats.html"
}),
]
}
const getRollupConfig = (pkg) => require(`${pkg}/rollup.external`)(path.resolve(__dirname, 'build', pkg));
const dependencies = !__PROD__ ? require('./packages').map(getRollupConfig) : [];
export default [preview, ...(dependencies.flat())];