Closed ohad182 closed 4 years ago
Hi @ohad182
You can use require('my-schema.yang')
instead of Yang.import
to load schema and its associated dependencies. And if you use webpack
or browserify
you can bundle the schema and its dependencies into your application. For webpack
you will need to use yang-loader.
Currently, there is no facility to support asynchronous dependency loading (such as dynamic fetching via HTTP GET for YANG schema files from a server).
Thanks for your comment,
How can i build the yang-loader library for web?
@saintkepha
Hi @ohad182 - please see below for using webpack along with custom loader (yang-loader) for building for web browser.
Hi @saintkepha,
I've installed yang-loader and set it to .yang files in my web project.
Now, since web production is a .js file and i have to import it as angular script - yang-loader fails since it performs:
var Yang = require('yang-js');
(which is not installed as npm package).
and i get error.
Module build failed (from ./node_modules/yang-loader/index.js):
Error: Cannot find module 'yang-js'
is there any solution to this? Thanks!
@ohad182 yang-loader has yang-js as a peerDependency. How are you using yang-js in your project without it being installed via npm or being placed inside node_modules/yang-js ?
@saintkepha I am using yang-js as mentioned in doc- clone -> build for web -> include the js file in angular.json
Got it.
First of all, the latest yang-js published package includes the browserified file inside the dist folder. You don’t need to build it yourself. Instead you can point it to yang-js/dist/yang.js for your angular project.
Secondly, using yang-loader along with webpack would ensure you do not need to use the browserified version at all. When you do require(“yang-js”) and other require(“my-schema.yang”) it will process it accordingly. You just need to make sure webpack will also process stuff inside node_modules/yang-js. Basically ensure it’s not excluded.
@saintkepha Thanks! you are right! it works! :)
Hi,
I am using this library within Angular, When parsing a schema that doesn't contain import it works well.
I need to parse a schema with custom imports (bundled within my assets).
is it possible to do something like: Yang.import(other_yang_content)
or: Yang.addImport('ietf-yang-types','assets/yangModules/ietf-yang-types.yang')
those imports should grab the files using http get from the hosting server.
Is there any way to accomplish this?
Thanks!