1
0
Fork 0
mirror of synced 2024-07-02 21:10:43 +12:00
budibase/packages/builder/rollup.config.js

230 lines
4.3 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"
2020-03-05 05:47:47 +13:00
import replace from "rollup-plugin-replace"
2020-05-07 21:53:34 +12:00
import json from "@rollup/plugin-json"
2019-07-13 21:35:57 +12:00
import path from "path"
const production = !process.env.ROLLUP_WATCH
2019-07-13 21:35:57 +12:00
const lodash_fp_exports = [
2020-05-07 21:53:34 +12:00
"flow",
"pipe",
"union",
"reduce",
"isUndefined",
"cloneDeep",
"split",
"some",
"map",
"filter",
"isEmpty",
"countBy",
"includes",
"last",
"find",
"constant",
"take",
"first",
"intersection",
"mapValues",
"isNull",
"has",
"isInteger",
"isNumber",
"isString",
"isBoolean",
"isDate",
"isArray",
"isObject",
"clone",
"values",
"keyBy",
"isNaN",
"keys",
"orderBy",
"concat",
"reverse",
"difference",
"merge",
"flatten",
"each",
"pull",
"join",
"defaultCase",
"uniqBy",
"every",
"uniqWith",
"isFunction",
"groupBy",
"differenceBy",
"intersectionBy",
"isEqual",
"max",
"sortBy",
"assign",
"uniq",
"trimChars",
"trimCharsStart",
"isObjectLike",
"flattenDeep",
"indexOf",
"isPlainObject",
"toNumber",
"takeRight",
"toPairs",
2020-03-22 22:21:18 +13:00
"remove",
"findIndex",
2020-03-25 00:35:46 +13:00
"compose",
"get",
2020-03-28 05:58:32 +13:00
"tap",
]
2019-07-13 21:35:57 +12:00
const lodash_exports = [
"flow",
"join",
"replace",
"trim",
"dropRight",
"takeRight",
"head",
"reduce",
"tail",
"startsWith",
"findIndex",
"merge",
"assign",
"each",
"find",
"orderBy",
"union",
]
2019-07-13 21:35:57 +12:00
const outputpath = "../server/builder"
2019-07-13 21:35:57 +12:00
2019-07-30 20:08:40 +12:00
const coreExternal = [
"lodash",
"lodash/fp",
"date-fns",
"lunr",
"safe-buffer",
"shortid",
"@nx-js/compiler-util",
]
2019-07-30 20:08:40 +12:00
const customResolver = resolve({
2020-05-07 21:53:34 +12:00
extensions: [
".mjs",
".js",
".jsx",
".json",
".sass",
".scss",
".svelte",
".css",
],
})
const projectRootDir = path.resolve(__dirname)
2019-07-13 21:35:57 +12: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"),
},
],
customResolver,
}),
copy({
targets: [
2020-04-02 22:44:42 +13:00
{ src: "src/index.html", dest: outputpath },
{ src: "src/favicon.png", dest: outputpath },
{ src: "assets", dest: outputpath },
{
src: "node_modules/@budibase/client/dist/budibase-client.esm.mjs",
dest: outputpath,
},
],
}),
2019-07-13 21:35:57 +12:00
2020-03-05 05:47:47 +13:00
replace({
2020-03-28 05:58:32 +13:00
"process.env.NODE_ENV": JSON.stringify(
production ? "production" : "development"
),
2020-03-05 05:47:47 +13:00
}),
svelte({
// enable run-time checks when not in production
dev: !production,
2020-03-13 03:23:29 +13:00
include: ["src/**/*.svelte", "node_modules/**/*.svelte"],
// we'll extract any component CSS out into
// a separate file — better for performance
css: css => {
css.write(`${outputpath}/bundle.css`)
},
}),
2019-07-13 21:35:57 +12:00
resolve({
browser: true,
dedupe: importee => {
return (
importee === "svelte" ||
importee.startsWith("svelte/") ||
coreExternal.includes(importee)
)
},
}),
commonjs({
namedExports: {
"lodash/fp": lodash_fp_exports,
lodash: lodash_exports,
shortid: ["generate"],
},
}),
url({
limit: 0,
include: ["**/*.woff2", "**/*.png"],
fileName: "[dirname][name][extname]",
emitFiles: true,
}),
url({
limit: 0,
include: ["**/*.css"],
fileName: "[name][extname]",
emitFiles: true,
}),
builtins(),
nodeglobals(),
// Watch the `dist` directory and refresh the
// browser on changes when not in production
!production && livereload(outputpath),
2019-07-13 21:35:57 +12:00
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser(),
json(),
],
}