Is there a way to include non-exporting js library into vue cli project? - vue.js

For the past 2 days I've been trying to include a non-exporting js library into my vue project and it seems to fail every time. The closest I've got to a working thing is with import *. It recognizes the commands in the library, but when I try to use them, it gives me an error that says:
the namespace is undefined
My question is - what is the best way to include a non-exporting (legacy) js library in a vue project?
import * as test from "library.js"

The webpack compiler can understand modules written as ES2015
modules, CommonJS or AMD. However, some third party libraries may
expect global dependencies (e.g. $ for jQuery). The libraries
might also create globals which need to be exported. These "broken
modules" are one instance where shimming comes into play.
Reference.
import './path/to/library.js'

Related

How do I import the flatlaf library to my project using intellij?

When compiling my main class I get this error:
Main.java:1: error: package com.formdev.flatlaf does not exist
import com.formdev.flatlaf.FlatLightLaf;
I have followed all the steps online, I have gone to project structure, libraries, "+", added the flatlaf.jar file and pressed on apply. I have also tried to revalidate caches. The JDK recognises the import of the library as well as all its functions as they all show up in the suggested and give no errors until you try to compile.
Make sure that you've added the library to the module dependencies.

How can you use multiple modules in a Raku project, if the modules are defined in the project?

I'm playing around with writing modules in Raku, when it made sense for me to break a piece of functionality off into another .rakumod file. How can I link these files together when I compile?
I tried to pull the other module to my main module via:
use MyProject::OtherModule;
But I get an error that it can't find this module even though they're side by side in the directory. I tried looking at some OSS projects in the Raku world, most of them are one file, the compiler Rakudo seems to use multiple module files but I can't figure out how they're linked.
Do I have to publish this module every time I want to run my project? How do I structure this if my project gets huge? Surely the best solution isn't to have it all in one file?
Edit: I should also note that I used this at the top of my new module too:
unit module MyProject::OtherModule;
When running locally, if you have your META6.json declared, you can use
raku -I. script.raku
and it will use the uninstalled versions, and you don't need to add any use lib in the script.

What is the difference between plugins and dependencies in the Vue.js UI?

When using the ui you have the option of installing dependencies and plugins.
I am confused about the difference between both of these.
For instance, I can install axios as a dependency and a plugin.
Do I need to do both? Why do one over the other?
My current understanding is that dependency is just that, it adds a package to your project while a plugin will add configuration as well.
Am I correct in thinking that?
A plugin is exactly what you described. It 'plugs into' another piece of software and adds functionality. A dependency on the other hand means that your software simply depends on something to function correctly - usually code.
In your axios example:
The axios plugin installs another prototype property on your Vue instance (this.$axios.. or whatever it is called) so it definitely adds a feature to Vue.
You could also only use Axios by itself and import it in the files you need
import axios from 'axios'. You don't add any feature to Vue itself - you just use another software within your app. Axios here is a dependency.
I will probably not be completely correct, but my understanding is
Plugins vs Dependencies
Command line
dependencies are installed via the command line as npm install <name> or npm install --save <name> to add the dependency to package.json
plugins are installed via the command line as vue add #scope/vue-cli-plugin-<name> or with the shorthand vue add #scope/<name>
Installation
dependencies are placed into your projects node_modules folder
plugins will invoke the generator.js script of the plugin being installed. This generator.js may add dependencies to package.json, add import statements to files in your project, add/alter existing components, or any of the various things listed under the generator api docs
Usage
dependencies will need to be imported into any file you use them in, or imported globally, before they are able to be used
plugins often will have already set up global imports, making them available in every file. Plugins will also often add additional scripts to package.json (which show up as tasks in the vue ui)

Browserify - How to include non-public purchased third party scripts

I am new to browserify and its usage is not completely clear to me although the benefits seem to be compelling.
I have a couple of questions and was hoping someone could clarify.
I've seen blog posts about using browserify-shim in the package.json to include third party libraries like jquery and bootstrap. I've also seen posts where tools like gulp are used generate the bundle file. I can't seem to find a good answer on why browserify-shim is required if tools like gulp are able to automate the process. Can someone please shed some light? Why is browserify-shim even required? I feel the gulp solution is a little cleaner although a little more involved. It won't pollute package.json with browserify specific stuff that is a build thing and therefore goes together with gulp (just my personal opinion)
How does one deal with third party libraries that are not in npm and also not public? For example, we purchase a script from a third party. That script is not any common js, but is a regular js file with some dependencies (example, on jquery and underscore).
Browserify lets you take the world of Node and bundle it up for delivery to a browser. It understands Node modules, which define dependencies via CommonJS require statements.
But what if you have some JS code or library that is not defined as a Node module and does not support CommonJS? Enter browserify-shim. It provides a shim wrapper around any script, like your private third party script, so that it can be defined as and used as a Node module that Browserify understands.
The use of browserify-shim is completely orthogonal to how you execute Browserify. There are basically two options there: A) Use Browserify's command line API or B) Use Browserify's JS API.
Using a build tool, like Gulp, implies the second option, since you'd use Browserify's JS API in your Gulp build script (i.e. gulpfile.js). A lot of people prefer the use of Gulp because it has a good ecosystem of plugins that allow you to do a lot more than just call Browserify (e.g. compile CoffeeScript, compile SASS, run JSHint, etc).
So, to answer your specific questions:
Browserify-shim is only required if you have JS code that is not written as a Node/CommonJS module that you need to bundle via Browserify. To do so, you will need to tell browserify-shim which files to shim as modules (and what dependencies they have) in package.json. Note that this is totally unrelated to Gulp; so you will need it whether you use Gulp or not.
What you describe is the perfect use-case of browserify-shim. Put your third party script(s) in your project, configure the files to be modules in package.json per b-shim's documentation, require them in your code, and execute Browserify to bundle them up with your code. You could also bundle them up separately, put them in their own project, etc - however you want to structure it.
A couple things to note:
You can shim just about any JS library this way.
Shimming a JS library to be a Node module changes global scope to be private scope. Hopefully everything in the library is namespaced so that all of its functionality can be exported as a single module, but if it's not, you might have to modify the shimmed code to explicitly attach things to window (which is easy but not recommended) or split the code up into separate files/modules.
Both Browserify and Gulp use streams in their JS API, but Browserify uses native Node streams while Gulp uses Vinyl streams. Since they don't play well together, you'll probably have to use vinyl-source-stream to adapt Gulp to Browserify (e.g. for renaming files in a Browserify pipeline), or use vinyl-transform to adapt Browserify to Gulp (e.g. wrap a Browserify stream for use in a Gulp pipeline).

How to load a dojo module using TypeScript

If I'm loading dojo from a CDN how do I import a module using TypeScript? The following code has no idea where to look for "dojo":
import dojo = module("dojo");
Is there a way to tell TypeScript to look elsewhere? Is there something similar to dojoConfig packages in TypeScript?
If you are referencing Dojo from a CDN you don't want to import it using the "external module" machinery because this expects modules in either a CommonJS or AMD format, and expects them to be on the file system. What you want to do is simply /// require a "typing" for Dojo (for example, see JQuery.d.ts that comes with TypeScript).
/// <require path="dojo.d.ts" />
What this will do is tell the compiler that all the types in Dojo are available in the compilation. It's up to you to ensure Dojo is included properly at runtime.
I am not sure whether a Dojo.d.ts file has already been created. There's a repository with a bunch of them that should at least serve as a good example if you want to start adding the typings yourself.