-
-
Notifications
You must be signed in to change notification settings - Fork 86
Using Parcel to compile your code
Using Parcel is a relatively simple way to compile the code you are using in uibuilder. This guide will show you how to move to using Parcel to compile your code as well as designing your web apps as single file components. If you don't want to use single file components the migration path would be slightly different, and isn't documented here.
I'm going to put it out there that I have written this from memory, so there may be an error or three. Please get back to me if you find any anomalies. Also, thank you to @unborn (Andy) from the Node-RED discourse forum for spending the time to help me through the migration process!
npm install -g parcel-bundler
Once you have created your flow in node-red with uibuilder and imported your "old" uncompiled code in, you will need to do some things to make the code work.
-
Data in the index.js needs to be a function, like this:
data: { }
-
Mounted is not a function, remove the function component. It should look like this:
mounted: function(){ }
-
You can not refer to your variables using the "app" prefixe.g.
app.[variable_name] will not work this.[variable_name] does work
-
If you want your design to use single file components, the structure of your files has to change Where you have 3x separate files for uibuidler index.css, index.html and index.js, you now have to create a single .vue file and paste the data from all three files into this file:
-
Your index.html data needs to be wrapped in a template:
<template> </template>
-
Your index.js data needs to be wrapped in a script:
<script> </script>
-
Your index.css data needs to be wrapped in a style:
<style> </style>
-
You will need a new .js file which is called "app.js" in this example. You can see from the example that a few things are being loaded:
- Vue itself
- the floorplan.vue file which is the single file component in this example
- the Router
- uibuilder
- bootstrap-vue
- fontawesome icons (optional)
Grab the app.js file from here: https://github.com/amilanov75/floorplan-uncompiled/blob/master/parcel/app.js
- You will need a new index.html file. In this example I have created a free account to access all the font-awesome icons, this is optional ie. delete the code if you don't want to us FA icons.
Grab the index.html file from here: https://github.com/amilanov75/floorplan-uncompiled/blob/master/parcel/index.html
- You will also need to create your own router.js file which you can expand on later with more projects:
Grab the router.js file from here: https://github.com/amilanov75/floorplan-uncompiled/blob/master/parcel/router.js
-
So in your project you will need the following files - thanks to @unborn for adding updates to clarify this:
a) [x].vue file - this is your single file component (this contains your original 3x uibuilder files, merged into 1x)
b) app.js - this renders App.vue
c) index.html - this loads app.js
d) router.js - this is the router file so you can point / create paths to multiple web pages / components
File (a) will need to sit in a new folder call "components", this will need to sit in the "src" folder -- thankyou to @unborn (from the node-red discourse forum) for pointing this out!
Files (b-d) will all sit in the "src" folder.
Once you have your code modified, as above, you will need to open up cmd and make your way to your "src" folder. From the src folder, you will need to run this:
parcel build index.html --public-url ./ --no-cache --out-dir ../dist/
Now you will need to restart the node-red server completely. @UnborN thinks this is because your uibuilder node needs to know that the data it is look for is in a new location. With my limited knowledge this makes sense to me i.e. This is so that Node-RED picks up the files in the "dist" folder rather than looking in the "src" folder
Now in the terminal window in Visual Studio Code run this command:
parcel watch index.html --public-url ./ --no-cache --out-dir ../dist/`
By using "watch" rather than "index" only the file you are working on will be re-compiled (from the looks of it), it works way faster than running the "index" command which seems to do a complete rebuild each time.
If all has gone well, you will have no errors in the terminal window and no errors in the web page debug console. If you do have errors, time to debug. Give me a shout if the guide needs updating. Thanks!
Please feel free to add comments to the page (clearly mark with your initials & please add a commit msg so we know what has changed). You can contact me in the Discourse forum, or raise an issue here in GitHub! I will make sure all comments & suggestions are represented here.
-
Walkthrough 🔗 Getting started
-
In Progress and To Do 🔗 What's coming up for uibuilder?
-
Awesome uibuilder Examples, tutorials, templates and references.
-
How To
- How to send data when a client connects or reloads the page
- Send messages to a specific client
- Cache & Replay Messages
- Cache without a helper node
- Use webpack to optimise front-end libraries and code
- How to contribute & coding standards
- How to use NGINX as a proxy for Node-RED
- How to manage packages manually
- How to upload a file from the browser to Node-RED
-
Vanilla HTML/JavaScript examples
-
VueJS general hints, tips and examples
- Load Vue (v2 or v3) components without a build step (modern browsers only)
- How to use webpack with VueJS (or other frameworks)
- Awesome VueJS - Tips, info & libraries for working with Vue
- Components that work
-
VueJS v3 hints, tips and examples
-
VueJS v2 hints, tips and examples
- Dynamically load .vue files without a build step (Vue v2)
- Really Simple Example (Quote of the Day)
- Example charts using Chartkick, Chart.js, Google
- Example Gauge using vue-svg-gauge
- Example charts using ApexCharts
- Example chart using Vue-ECharts
- Example: debug messages using uibuilder & Vue
- Example: knob/gauge widget for uibuilder & Vue
- Example: Embedded video player using VideoJS
- Simple Button Acknowledgement Example Thanks to ringmybell
- Using Vue-Router without a build step Thanks to AFelix
- Vue Canvas Knob Component Thanks to Klaus Zerbe
-
Examples for other frameworks (check version before trying)
- Basic jQuery example - Updated for uibuilder v6.1
- ReactJS with no build - updated for uibuilder v5/6
-
Examples for other frameworks (may not work, out-of-date)
-
Outdated Pages (Historic only)
- v1 Examples (these need updating to uibuilder v2/v3/v4/v5)