Comments (5)
@bjoluc any thoughts on this one? I'm guessing there is some config needed because the VAS plugin is not using the TS template, and that we may want to adjust the package build for this scenario.
from jspsych-contrib.
@d-bohn The VAS plugin is meant to be included in a script tag and works with global variables, most notably the jsPsychModule
variable (which is defined when jsPsych is loaded as a script). There is a hack here based on the webpack shimming guide: If you npm i -D impors-loader exports-loader
, you can use
import jsPsychHtmlVasResponse from "imports-loader?type=commonjs&imports=single|jspsych|jsPsychModule!exports-loader?type=commonjs&exports=single|jsPsychHtmlVasResponse!@jspsych-contrib/plugin-html-vas-response";
like any other core plugin.
I'm guessing there is some config needed because the VAS plugin is not using the TS template, and that we may want to adjust the package build for this scenario.
@jodeleeuw We might be able to add an extra build step that creates an ES/commonjs module based on the IIFE file. But that would be pretty hacky and nothing I'd like to maintain. Maybe mention the imports-loader exports-loader workaround somewhere instead?
I just put together a generic webpack config extension I think I'll add to jsPsych builder (@d-bohn you can simply apply this to your webpack config
object and just import jsPsychHtmlVasResponse from "@jspsych-contrib/plugin-html-vas-response";
):
import { readFileSync } from "fs";
// Transform IIFE plugins from `@jspsych-contrib` to modules using `imports-loader` and `exports-loader`
config.module.rules.push({
test: (resource) => resource.includes("/@jspsych-contrib/plugin-"),
use: (info) => {
if (info.descriptionData.main) {
// The `main` field is not set in the IIFE plugin template, so we consider everything with
// a `main` field non-IIFE and ignore it here.
return [];
}
// Extract the global variable name of the plugin
const pluginVarName = /^var ([a-zA-Z]+) = \(function/m.exec(
readFileSync(info.resource).toString()
)[1];
return [
"imports-loader?type=commonjs&imports=single|jspsych|jsPsychModule",
`exports-loader?type=commonjs&exports=single|${pluginVarName}`,
];
},
});
from jspsych-contrib.
We might be able to add an extra build step that creates an ES/commonjs module based on the IIFE file. But that would be pretty hacky and nothing I'd like to maintain. Maybe mention the imports-loader exports-loader workaround somewhere instead?
That works for me; thanks for the clarification!
from jspsych-contrib.
Hi folks, would it be helpful for me to simply rewrite the code using the TS template? I would be happy to if it would make it more usable.
from jspsych-contrib.
@kinleyid That's not directly necessary given the workaround - but it would sure be great!
from jspsych-contrib.
Related Issues (8)
- Add a who-used-jsPsych section in the readme / docs
- Setup changesets HOT 4
- Mediapipe face tracking extension HOT 3
- extension-touchscreen-buttons
- Latest version of html-vas-response doesn't seem to be on NPM? HOT 2
- self-paced-reading doesn't record data HOT 11
- make it clearer how to browse the list of plugins available here. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jspsych-contrib.