How to include Javascript files in multiple projects? [duplicate] - javascript

This question already has answers here:
MVC Razor, Include JS / CSS files from another project
(4 answers)
Closed 8 years ago.
We have a website that pulls data from a separate web-services site via AJAX. (MVC 5 for the former, WebAPI for the latter.)
We have some javascript classes defined to make interfacing with these web-services simpler. These classes need to be loaded in the pages of the website, but I'd really prefer that they actually live in the web-services site project.
Not only are they conceptually linked to the web services that they wrap, I also need to include them in a separate web-service-unit test project.
I'd thought that I'd be able to put the files in the web-services project, and then to include them in the website project and the unittest project, as links. (Add Existing Item -> Add as Link)
The problem is that this doesn't work. When I do a script include of the linked file, the browser can't see it. In actual fact, the file isn't there, there's just a notification in the .csproj file pointing to where it really is, and the web server doesn't understand that.
So, what should I do, instead? I'm sure others have had the problem.

I think that problem could be related to following facts:
JavaScript file it's not copied inside script folder of destination website
IIS express point as basedir at destination website root folder and use script folder where the file it's not copied
You can inspect this problem trying to display source code of page and click on external JavaScript file; you should get a 404 error page where display the wrong path.
If you try to deploy the application, the external linked JavaScript file should be deployed correctly inside script folder.
For solve this problem that should affect development environment you could create a custom post build script that take care of copy and replace file to destination folder script.
Hope this helps
Maurizio

Related

Can Gatsby/GraphQL leverage javascript files?

I'm porting over my site from a different site framework to Gatsby. I am currently importing my old site and sourcing the files using gatsby-source-filesystem however this only gives me information about the files versus the contents. I've ran into some transformers for the markdown files as part of my exploration, but I want to know if there's anyway to leverage my javascript (.js) and handlebars (.hbs) files to obtain the objects within them and possibly output them onto a page.

How to render openFrameworks app to host on browser

I'm new to both openFrameworks and this compiler called Emscripten.
After struggling for a few days, I was able to compile my openFrameworks/C++ code into js but Emscripten gives me an html file with a lot of junk included (For example, there is a header and footer -
http://openframeworks.cc/setup/emscripten/)
I'm trying to host the video/animation itself like it is on this page (http://www.syedrezaali.com/#/great-scott/) but I have no idea how to go about it. Can anyone help me out?
Thank you
If you follow OF's guidelines Emscripten generates not only the html file but also some other files (I think it's 4 files in total). You need to copy all of those into your site, then link to the html file.
Notice that while developing you can use
emrun --browser chrome bin/yourSample.html
To open the file, but you cannot just open the .html file (not sure why). See this guidelines as well, which are linked in the OF tutorial.
Update
I haven't tested this, but it looks like OF loads a site template. See this makefile for emscripten, you may specify your own via PROJECT_EMSCRIPTEN_TEMPLATE or you could just change the template OF uses.

How to reference a TypeScript file from a web page

Preamble
I can get this to work but I'm not sure I'm using the technology as Microsoft intended.
Context
A web page can refer to a JS file containing JavaScript by means of a reference tag like this:
<script src="Scripts/jquery.js"></script>
In the above example, the JS file is part of a Visual Studio ASPX.NET project. It was both placed in the project Scripts folder and added to the project by Nuget.
Having added a Typescript file to an existing ASP.NET project, I would like to use the generated JS from an ASPX web page.
Instructing Solution Explorer to show all files reveals that the expected JS file has indeed been generated on the expected path.
Am I using this correctly? What is the recommended method?
There are a couple of ways one might go about things.
Refer directly to the generated JS file
I was concerned that files not part of a project would be excluded from a web server deployment, but have since determined that they are deployed.
Add some kind of reference to the Typescript file
It would be great if there were some syntax for a reference to the TS file that will be transformed into a script tag referring to the generated JS file. Alas, if this exists it's not very well publicised.
In VS2015, dragging the TS file onto an HTML or ASPX page in the editor will insert a link tag referring to the corresponding JS file.
DO NOT use server URL rewriting to remap references to the TS file to the JS file. This interferes with VS and browser debug support via source map files.

Why not to include a .js file containing Express.js code into an HTML file?

Not an unsolved problem, but rather a technical question, which I hope is valuable enough to ask.
As a beginner web developer, I attempted to give a variable from a .js file to an .html file, to display a variable from the former on-screen - I desired to do so by the <script src=... parameter. The .js file I wanted to include in the .html is the one that contains the code, which creates the HTTP server (as of yet a simple one) and loads the .html file.
I was told that it is a bad idea, and I should use JSON objects instead. THe problem is therefore solved, but I'm interested: why was it a bad idea to include the script of Express.js within the HTML file?
Express.js is Node.js web application framework. Lets simply call it backend javascript, which means it's designed to be run not in browser, but as part of Node.js application.
Just FYI:
There is a way to 'run' some Node modules in browser. There is tool called browserify .
Here what they are saying on their web site:
Use many of the tens of thousands of modules on NPM in the browser
I'm afraid that Express.js is not one of those 'many' modules.

One JavaScript code file for multiple locations

We are developing multiple Java EE applications (8 for the moment) that are all based on the same sort of code. However, all the apps are clearly separated as different projects in Eclipse, they all have their own folder on Windows Explorer, and they all have their own repo on the Git server.
The idea was to put the redundant code somewhere (another project named "core"), and use it on every apps automatically without having to recode the same thing 8 times.
For the Java part, we did a "link source" in each project, which create sort of a symlink inside Eclipse to the "core" project, and use the specified "core" package in Java source with no problem.
But it doesn't work so well for the JavaScript/CSS part. I have absolutely no clue about how to code my redundant JS/CSS onto the "core" project, and use it elsewhere without having to manually copy it each and every time I modify it.
I think you should look into git for a solution to your problem. After all you still want the js file to be included in every project, but be maintained in a seperate project (as far as I understand it). There ought to be some sort of submodules and/or commit-handles or whatever to solve this using git.
This is what the User Library functionality in the JavaScript Include Path properties of your project is for.

Categories