budibase/packages/builder/rollup.config.js

154 lines
3.8 KiB
JavaScript
Raw Normal View History

import alias from "@rollup/plugin-alias"
import svelte from "rollup-plugin-svelte"
import resolve from "rollup-plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import url from "rollup-plugin-url"
import livereload from "rollup-plugin-livereload"
import { terser } from "rollup-plugin-terser"
import builtins from "rollup-plugin-node-builtins"
import nodeglobals from "rollup-plugin-node-globals"
import copy from "rollup-plugin-copy"
import css from "rollup-plugin-css-only"
2020-03-04 17:47:47 +01:00
import replace from "rollup-plugin-replace"
2020-05-07 11:53:34 +02:00
import json from "@rollup/plugin-json"
import html from "rollup-plugin-html"
2019-07-13 11:35:57 +02:00
import path from "path"
const production = !process.env.ROLLUP_WATCH
const outputpath = "../server/builder"
2019-07-30 10:08:40 +02:00
const coreExternal = [
"lodash",
"lodash/fp",
"date-fns",
"lunr",
"safe-buffer",
"shortid",
"@nx-js/compiler-util",
]
2019-07-30 10:08:40 +02:00
const customResolver = resolve({
2020-05-07 11:53:34 +02:00
extensions: [
".mjs",
".js",
".jsx",
".json",
".sass",
".scss",
".svelte",
".css",
],
})
const projectRootDir = path.resolve(__dirname)
2019-07-13 11:35:57 +02:00
export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: `${outputpath}/bundle.js`,
},
plugins: [
alias({
entries: [
{
find: "components",
replacement: path.resolve(projectRootDir, "src/components"),
},
{
find: "builderStore",
replacement: path.resolve(projectRootDir, "src/builderStore"),
},
{
find: "stores",
replacement: path.resolve(projectRootDir, "src/stores"),
},
2020-06-15 17:41:31 +02:00
{
find: "constants",
replacement: path.resolve(projectRootDir, "src/constants"),
},
{
find: "analytics",
replacement: path.resolve(projectRootDir, "src/analytics"),
},
],
customResolver,
}),
copy({
targets: [
2020-04-02 11:44:42 +02:00
{ src: "src/index.html", dest: outputpath },
{ src: "src/favicon.png", dest: outputpath },
{ src: "assets", dest: outputpath },
2020-06-19 13:36:03 +02:00
{
src: "node_modules/@budibase/bbui/dist/bbui.css",
dest: outputpath,
},
2020-10-27 14:04:32 +01:00
{
src: "node_modules/remixicon/fonts/*",
dest: outputpath,
},
],
}),
2019-07-13 11:35:57 +02:00
2020-03-04 17:47:47 +01:00
replace({
2020-03-27 17:58:32 +01:00
"process.env.NODE_ENV": JSON.stringify(
production ? "production" : "development"
),
2020-07-13 19:09:32 +02:00
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
2020-07-13 20:44:42 +02:00
"process.env.POSTHOG_URL": JSON.stringify(process.env.POSTHOG_URL),
2020-07-14 17:00:58 +02:00
"process.env.SENTRY_DSN": JSON.stringify(process.env.SENTRY_DSN),
2020-03-04 17:47:47 +01:00
}),
svelte({
// enable run-time checks when not in production
dev: !production,
include: [
"src/**/*.svelte",
"node_modules/**/*.svelte",
"../../../bbui/src/**/*.svelte",
],
// we'll extract any component CSS out into
// a separate file — better for performance
css: css => {
2020-11-09 19:04:55 +01:00
css.write("bundle.css")
},
}),
2019-07-13 11:35:57 +02:00
2020-09-09 17:27:46 +02:00
// export all CSS imported in the JS to it's own bundle
css({
2020-09-09 17:27:46 +02:00
output: `${outputpath}/external.css`,
}),
resolve({
browser: true,
dedupe: importee => {
return (
importee === "svelte" ||
importee.startsWith("svelte/") ||
coreExternal.includes(importee)
)
},
}),
2020-11-18 12:24:01 +01:00
commonjs(),
url({
limit: 0,
include: ["**/*.woff2", "**/*.png"],
fileName: "[dirname][name][extname]",
emitFiles: true,
}),
builtins(),
nodeglobals(),
// Watch the `dist` directory and refresh the
// browser on changes when not in production
!production && livereload({ watch: outputpath, delay: 500, port: 35730 }),
2019-07-13 11:35:57 +02:00
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
json(),
html(),
],
}