I’ve uploaded an html template to my assets/html folder. Can I access this in JS/TS without using the html bridge component in xml?
Yes, you can, with a TypeScript app you can access the file using the import statement.
You may need to add the Node JS Package raw-loader
as a dependency in package.json
e.g.
import txt from 'raw-loader!./file.txt';
// OR
const txt = require('raw-loader!./file.txt')
I’ve added raw-loader, still getting ‘Cannot find module’raw-loader!./… or its corresponding type declarations’
Is there a way to display the app file tree, or a reference? It’s not clear where in the structure I should go to access assets/html
, i.e. is it in mobile, app, or another root folder?
Do I need to import raw-loader from ‘raw-loader’ in each view/module where I want to use this as well?
Thanks for the feedback, we have a solution that will require a few changes in order to import the asset:
- Create a new app module in Oxide called raw-loader
- Add the following to the module
declare module '!!raw-loader!*' {
const contents: string
export = contents
}
- Update your view where you want to import the asset to the following (import the new module and update the path of the asset you are importing)
import '~/lib/raw-loader';
import file from '!!raw-loader!~/../../mobile/html/file.html';
async function init() {
console.log(file);
}
In this case, you’ll notice the file I’m importing in this example is called file.html