From 4484a1ee6f41ec2894fe498910528750d71dc6e0 Mon Sep 17 00:00:00 2001 From: CJ Green <44074998+okaycj@users.noreply.github.com> Date: Wed, 15 May 2024 13:41:36 -0400 Subject: [PATCH] Update rollup config This commit will do two things. First, this will only bundle iife configs. Second, it adds the data package as an external dependency. --- packages/data/rollup.config.mjs | 26 +++++++++---------- packages/lookit-initjspsych/rollup.config.mjs | 4 +-- packages/record/rollup.config.mjs | 2 +- packages/surveys/rollup.config.mjs | 2 +- rollup.mjs | 25 ++++++++++++++++++ 5 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 rollup.mjs diff --git a/packages/data/rollup.config.mjs b/packages/data/rollup.config.mjs index 79c0d80e..a985b195 100644 --- a/packages/data/rollup.config.mjs +++ b/packages/data/rollup.config.mjs @@ -1,18 +1,18 @@ -import { makeRollupConfig } from "@jspsych/config/rollup"; import { nodeResolve } from "@rollup/plugin-node-resolve"; import dotenv from "rollup-plugin-dotenv"; +import { makeRollupConfig } from "../../rollup.mjs"; -const config = makeRollupConfig("chsData"); +export const iifeNameData = "chsData"; -config.map((c) => { - c.plugins = [ - nodeResolve({ - browser: true, - preferBuiltins: false, - }), - dotenv(), - ...c.plugins, - ]; +export default makeRollupConfig(iifeNameData).map((config) => { + return { + ...config, + plugins: [ + // Resolve node dependencies to be used in a browser. + nodeResolve({ browser: true, preferBuiltins: false }), + // Add support for .env files + dotenv(), + ...config.plugins, + ], + }; }); - -export default config; diff --git a/packages/lookit-initjspsych/rollup.config.mjs b/packages/lookit-initjspsych/rollup.config.mjs index f314d59d..ab232468 100644 --- a/packages/lookit-initjspsych/rollup.config.mjs +++ b/packages/lookit-initjspsych/rollup.config.mjs @@ -1,3 +1,3 @@ -import { makeRollupConfig } from "@jspsych/config/rollup"; - +import { makeRollupConfig } from "../../rollup.mjs"; +// This package name needs to be unique export default makeRollupConfig("chsInitJsPsych"); diff --git a/packages/record/rollup.config.mjs b/packages/record/rollup.config.mjs index e2f62569..430db91d 100644 --- a/packages/record/rollup.config.mjs +++ b/packages/record/rollup.config.mjs @@ -1,3 +1,3 @@ -import { makeRollupConfig } from "@jspsych/config/rollup"; +import { makeRollupConfig } from "../../rollup.mjs"; // This package name needs to be unique export default makeRollupConfig("chsRecord"); diff --git a/packages/surveys/rollup.config.mjs b/packages/surveys/rollup.config.mjs index a4bc4658..ead8352d 100644 --- a/packages/surveys/rollup.config.mjs +++ b/packages/surveys/rollup.config.mjs @@ -1,3 +1,3 @@ -import { makeRollupConfig } from "@jspsych/config/rollup"; +import { makeRollupConfig } from "../../rollup.mjs"; // This package name needs to be unique export default makeRollupConfig("chsSurvey"); diff --git a/rollup.mjs b/rollup.mjs new file mode 100644 index 00000000..d86c7fc0 --- /dev/null +++ b/rollup.mjs @@ -0,0 +1,25 @@ +import { makeRollupConfig as jsPsychMakeRollupConfig } from "@jspsych/config/rollup"; +import { iifeNameData } from "./packages/data/rollup.config.mjs"; + +export function makeRollupConfig(iifeName) { + return jsPsychMakeRollupConfig(iifeName).map((config) => { + return { + ...config, + // Add data package as external dependency + external: [...config.external, "@lookit/data"], + output: config.output + // Only build iife bundles + .filter((output) => output.format === "iife") + .map((output) => { + return { + ...output, + globals: { + ...output.globals, + // Explicitly state data's iife name + "@lookit/data": iifeNameData, + }, + }; + }), + }; + }); +}