-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
86 lines (79 loc) 路 2.22 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
import svelte from "rollup-plugin-svelte"
import commonjs from "rollup-plugin-commonjs"
import resolve from "rollup-plugin-node-resolve"
import serve from "rollup-plugin-serve"
import html from "rollup-plugin-bundle-html"
// import typescript from "rollup-plugin-typescript2";
// import tscompile from "typescript";
import { terser } from "rollup-plugin-terser"
import livereload from "rollup-plugin-livereload"
import bundleSize from "rollup-plugin-bundle-size"
import babel from "rollup-plugin-babel"
import sveltePreprocess from "svelte-preprocess"
import pkg from "./package.json"
const name = pkg.name
.replace(/^(@\S+\/)?(svelte-)?(\S+)/, "$3")
.replace(/^\w/, m => m.toUpperCase())
.replace(/-\w/g, m => m[1].toUpperCase())
const isProd = process.env.NODE_ENV === "production"
const isDev = process.env.NODE_ENV === "development"
const isTest = process.env.NODE_ENV === "test"
const preprocess = sveltePreprocess({
scss: {
includePaths: ["src"]
},
postcss: {
plugins: [require("autoprefixer")]
}
})
const plugins = [
commonjs({ include: "node_modules/**" }),
// typescript({ typescript: tscompile }),
svelte({
dev: isProd ? false : true,
extensions: [".svelte"],
// preprocess: require("./svelte.config.js").preprocess,
preprocess,
css: isTest ? false : css => css.write("build/css/style.css")
}),
resolve({
browser: true,
dedupe: importee => importee === "svelte" || importee.startsWith("svelte/")
}),
html({
template: "src/index.html",
dest: "build",
filename: "index.html"
})
]
if (isDev) {
plugins.push(
serve({
open: false,
openPage: "/index.html",
historyApiFallback: "/index.html",
contentBase: ["./build"]
}),
livereload({
watch: "build"
})
)
} else if (isProd) {
// Minify
plugins.push(terser({ sourcemap: true, mangle: true }))
plugins.push(babel({
extensions: [".js", ".mjs", ".svelte"],
include: ["src/**"],
exclude: ["node_modules/**"],
runtimeHelpers: true
}))
}
plugins.push(bundleSize())
export default {
input: isProd ? "src/date-range-picker/index.js" : "src/index.js",
output: [
{ file: pkg.module, format: "es" },
{ file: pkg.main, format: "umd", name }
],
plugins
}