What's the best way to configure a WordPress plugin with rslib? #496
Replies: 4 comments 3 replies
-
If you're trying to preserve export default defineConfig({
lib: [
{
format: "esm",
syntax: "es2022",
dts: true,
},
{
format: "cjs",
+ autoExternal: false,
syntax: "es2015",
},
], |
Beta Was this translation helpful? Give feedback.
-
@fi3ework Thanks, but no. More problems: I've disabled Then tested locally using Docker/Local/Flywheel.
Why compile using In short: I wonder, do you have enough unit test coverage regarding the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the advice @fi3ework to give UMD a try. Unfortunately, there are still problems. What I did: (1) Added a UMD Bundle {
format: "umd",
// This will include all the JS code into one single file without
// the use of require()
autoExternal: false,
umdName: "VideomailClient",
output: {
distPath: {
root: "./dist/umd/",
},
},
}, See https://github.com/binarykitchen/videomail-client/blob/master/rslib.config.ts#L45 (2) Included that UMD bundle in the WordPress plugin function copyVideomailClient() {
return gulp
.src("node_modules/videomail-client/dist/umd/index.js")
.pipe(gulp.dest("target/js/videomail-client"));
} See https://github.com/binarykitchen/videomail-for-ninja-forms/blob/develop/gulpfile.js#L58 (3) Loaded it into WordPress wp_enqueue_script(
'nf-videomail-client',
NF_Videomail::$jsUrl . 'videomail-client/index.js',
array(),
NF_Videomail::VERSION
); (4) Error when loading locally First error thrown: index.js?ver=5.4.0:4152 Uncaught TypeError: Cannot read properties of undefined (reading 'createNanoEvents')
at <static_initializer> (index.js?ver=5.4.0:4152:59) When i debug, it's this bundled code: // EXTERNAL MODULE: external "nanoevents"
var external_nanoevents_ = __webpack_require__("nanoevents");
class Despot {
name;
options;
// The one and only, instantiate it only once and keep it global.
// https://github.com/ai/nanoevents
static EMITTER = (0, external_nanoevents_.createNanoEvents)();
constructor(name, options){
this.name = name;
this.options = options;
} There appears to be a problem around webpack_require, I think? I've set autoExternal to false, why still the use of require? |
Beta Was this translation helpful? Give feedback.
-
I think I made a mistake and have fixed it on my side. Thanks for your advice and suggestions. |
Beta Was this translation helpful? Give feedback.
-
Good evening,
Before, I compiled WordPress plugins with gulp all fine. Switched to rslib and stuck. Here is an error message:
How can I tell rslib to build without using
require
for WordPress plugins, and to include all the external dependencies without require?It's this library (Videomail-Client), I'm trying to include.
In rslib.config.ts, you can see this configuration:
The ESM syntax works fine for my homepage, but not the CJS syntax for WordPress plugins.
Is there an option to compile all the external dependencies inside one single CJS file without the need for the require command? WordPress does not support require on the client-side.
Any thoughts?
Thanks for any inputs,
cheers M.
Beta Was this translation helpful? Give feedback.
All reactions