Replies: 4 comments 4 replies
-
Import statements are not natively supported in JavaScript unless you are using modern components. They only work if you use a build step. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you mean by "using modern components". I tend to have the latest stable browser versions. They do support import as far as I know. But more stuff needs to line up... But maybe what I'm asking for is the wrong thing. I think what's I'm bumping against is that the build-less mode is great for small demos but really doesn't scale. Just now, I needed to fix some bugs in vue-svg-gauge that the author evidently is not fixing. Since it's really all contained in a .vue file I naively copied that into my page's src directory. But no, it doesn't work 'cause it's importing TWEEN and lodash get. So now I either have to track down those dependencies or I need to go the other route of forking the repo, packaging my own module so I get a min.js file I can drop in. Painful. NB: I'm not a regular JS programmer and am trying to avoid having to go through the whole process of figuring out which build system is the best here, how to use it, etc. I've done that in the past but every 2 years it all changes, so very frustrating... |
Beta Was this translation helpful? Give feedback.
-
Just a note to say that I've been messing with a build step again - using Snowpack which I find vastly better than other build tools. I've also now worked out how to use the build tools own dev server with uibuilder complete with live reload. Previously I'd only managed to do that with Svelte. I updated the tech docs with this info but only in the vNext branch so if you've time, please have a go with that branch. It is a bit of a pain because you have to change your html urls and add a couple of parameters to the I also plan to revisit the Snowpack config because I think that I could arrange the front-end code so that the Snowpack build and dev processes deal with the code differences. I also think there are some ways that Snowpack could be integrated with uibuilder itself such that it provided a dynamic rebuild process within uibuilder. Just so that you know, Snowpack has a plugin for Vue which gives you an almost configureless build process. Here is an example config file that you would have in the root folder of your front-end code. // Snowpack Configuration File
// See all supported options: https://www.snowpack.dev/reference/configuration
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
// Use the ./src folder for source files
'src': '/'
},
// Set extra environment variables for build-time replacement in code
env: {
// __SNOWPACK_ENV__.MODE & __SNOWPACK_ENV__.NODE_ENV are both set to process.env.NODE_ENV
// All other vars HAVE to start with "SNOWPACK_PUBLIC_"
// Use in code as "__SNOWPACK_ENV__.MODE"
// or destructured as "const {MODE} = __SNOWPACK_ENV__;"
// In HMTL, use as "%MODE%"
}
plugins: [
// "@morgul/snowpack-plugin-vue2", // Vue2. https://github.com/Morgul/snowpack-plugin-vue2
// ["@snowpack/plugin-optimize", { /* options */ }], // Optimise unbundled assets https://www.npmjs.com/package/@snowpack/plugin-optimize
// ['snowpack-plugin-replace', { /* options */ }], // Replace Str/regex. https://www.npmjs.com/package/snowpack-plugin-content-replace
// ['snowpack-plugin-content-replace', { /* options */ }], //Replace strings in output files. https://www.npmjs.com/package/snowpack-plugin-content-replace
// Plugins for conv to JS or html ...
],
packageOptions: {
/* ... */
},
// Configure the dev server
devOptions: {
//openUrl: 'nr'
},
buildOptions: {
// Use the ./dist folder for build files
'out': 'dist',
//watch: true, // Can be used to auto-rebuild the dist folder if not using snowpack dev server
},
module: {
//
},
}; As you can see, you only really need a couple of lines of configuration, the rest are my comments and reminders. |
Beta Was this translation helpful? Give feedback.
-
Hi, +1 for using/supporting ESM module format. This is not an upcoming standard, this is the standard. Browser support without any build tools seems to be the lesser problem, as it works out-of-the-box on all current browsers: However, if you use third-party frameworks or modules, the problem is that not all of those come with a ESM type distributable (or bundled) version that runs in the browser. For ESM modules to work out-of-the-box in the browser, the imports must use real existing (relative) path names including the ".js" file suffix, that is not the case if you use a build system where the imported dependencies are resolved by the system. That is often forgotten and it is a nuisance at least. If you design your own components however, I don't see a reason why not to design this from the ground up using ESM modules. |
Beta Was this translation helpful? Give feedback.
-
Looking at various vue libraries they all show usage with
import
statements. For example https://github.com/skalinichev/uplot-wrappers has:I don't know whether it's at all possible to support this stuff in uibuilder or whether it's already possible, but it sure would be nice. As it is, one has to install the npm module and then manually track down which files need to be loaded directly from the html. IMHO sorting this out should be higher priority than some of the editor improvements listed on the projects page, but that's just me :-).
Beta Was this translation helpful? Give feedback.
All reactions