-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
155 lines (143 loc) · 3.89 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
146
147
148
149
150
151
152
153
154
155
import {terser} from "rollup-plugin-terser"
import livereload from "rollup-plugin-livereload"
import svelte from "rollup-plugin-svelte"
import commonjs from "@rollup/plugin-commonjs"
import resolve from "@rollup/plugin-node-resolve"
import sveltePreprocess from "svelte-preprocess"
import css from "rollup-plugin-css-only"
import fs from "fs"
import {copySync} from "fs-extra"
import path from "path"
import babel from "@rollup/plugin-babel"
const pdfJsWorker = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.worker.js")
// const pdfJs = path.resolve(__dirname, "node_modules/pdfjs-dist/es5/build/pdf.js")
// const pdfJsWorker = path.resolve(__dirname, "node_modules/pdfjs-dist/build/pdf.worker.min.js")
// const pdfJs = path.resolve(__dirname, "node_modules/pdfjs-dist/build/pdf.min.js")
let production = !process.env.ROLLUP_WATCH
let app_type = process.env.APP_TYPE || "pro"
let app_version = process.env.npm_package_version
let constants = {
demo: {
app_id: "pdfviewdem",
app_name: "Docs View demo",
icon: "pdfviewdemo.png"
},
pro: {
app_id: "docviewpro",
app_name: "Docs View",
icon: "pdfviewpro.png"
},
demo_old: {
app_id: "pdfviewdem"
},
pro_old: {
app_id: "pdfviewpro"
}
}
function serve() {
let server
function toExit() {
if (server) server.kill(0)
}
return {
writeBundle() {
if (server) return
server = require("child_process").spawn(
"npm",
["run", "start", "--", "--dev"],
{
stdio: ["ignore", "inherit", "inherit"],
shell: true
}
)
process.on("SIGTERM", toExit)
process.on("exit", toExit)
}
}
}
function replaceInFiles(filename) {
fs.readFile("src/files/" + filename, "utf8", function(err, data) {
if (err) {
return console.log(err)
}
let result = data.replace(/{{app_id}}/g, constants[app_type].app_id)
result = result.replace(/{{app_name}}/g, constants[app_type].app_name)
result = result.replace(/{{app_version}}/g, app_version)
fs.writeFile("build/" + filename, result, "utf8", function(err) {
if (err) return console.log(err)
})
})
}
const copyToDist = () => ({
generateBundle() {
copySync("assets/", "build/")
copySync(pdfJsWorker, "build/pdf_worker.js")
replaceInFiles("accessoryservices.xml")
replaceInFiles("config.xml")
copySync("src/files/" + constants[app_type].icon, "build/icon.png")
}
})
export default {
external: ["tizen", pdfJsWorker, "webapis"],
input: "src/index.js",
output: {
file: "build/bundle.js",
format: "iife",
name: "app",
globals: {
[pdfJsWorker]: "PdfjsWorker",
// [pdfJs]: "Pdfjs",
"tizen": "tizen",
"webapis": "webapis"
}
},
plugins: [
{
// provide node environment on the client
transform: (code) => ({
code: code.replace("is_dev", `${!production}`).replace("app_type", `"${app_type}"`).replace("app_name", constants[app_type].app_name),
map: {mappings: ""}
})
},
svelte({
preprocess: sveltePreprocess(),
compilerOptions: {
dev: !production
}
}),
css({output: "bundle.css"}),
resolve({
browser: true,
dedupe: ["svelte"]
}),
commonjs(),
copyToDist(),
production && babel({
extensions: [".js", ".mjs", ".html", ".svelte"],
babelHelpers: "runtime",
exclude: ["node_modules/@babel/**", "node_modules/core-js/**"],
presets: [
[
"@babel/preset-env",
{
targets: "> 0.25%, not dead",
useBuiltIns: "usage",
corejs: 3
}
]
],
plugins: [
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-transform-runtime",
{
useESModules: false
}
]
]
}),
!production && serve(),
!production && livereload("build"),
production && terser()
]
}