Is there a way to specify an alternate AMD loader for intern?
I use ESRI's ArcGIS API for JavaScript and unfortunately don't have access to their source code. So I'm stuck having to load their code from here.
Their API is build on top of Dojo, so I'm thinking that I should be able to test with intern if I can point it at their loader instead of the one that comes with intern.
As of Intern 1.2, you can specify an alternate AMD loader for the browser client by changing <script src="node_modules/dojo/dojo.js"></script> within client.html, and for the command-line client by changing var req = require('dojo/dojo') in client.js. It is not currently possible to change the test runner’s loader (runner.js) because the Node.js module loader relies on being able to find the overridden Node.js require in another specific (non-standard) location.
Related
Recently I was create react app using vite , it is lightweight , less config and fast then compare with webpack . now my question is , is it required bable configuration in Vite project
No, vite does automatic syntax transforms but it only targets browsers that support es modules (firefox & chrome started supporting it around 2018). If you want to support new js features in older browsers you need to add polyfills though. You can read about the exact behavior and how to support even older browsers here.
I think that question need more information about that topic.
Vite.js uses the built-in JavaScript support of the browser, so you don't need to explicitly configure the JavaScript version in Vite.js itself.
When I said Vite.js uses the built-in JavaScript support of the browser, I meant that Vite.js relies on the JavaScript engine of the browser to interpret and run the JavaScript code in your application. The JavaScript engine is the component of the browser that executes JavaScript code. When you visit a web page that contains JavaScript, the browser runs the JavaScript code using its built-in JavaScript engine. This means that the version of JavaScript that is supported by your application is determined by the version of the JavaScript engine that is built into the browser. In the case of Vite.js, the JavaScript code in your application is not transpiled or otherwise modified before being run by the browser. However, if your application uses modern JavaScript syntax that is not supported by the target browsers, you will need to transpile the code to an older version of the language that is supported. In that case, you can use Babel.
No, it is already setup on the background. However if you'd like to adjust Babel's config you can do it. Read the docs here: https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md
I have a C++ Node.js add-on. I can run use v8's RunScript to run execute javascript in the context of the native module.
Now, I also would like to execute a JS statement that contains require.
Unfortunately, the native module is setup in such a way that the context does not include require. I get the error:
ReferenceError: require is not defined
Is there a way prepare the native module's context such that it behaves like a standard node.js module ? i.e. it provides the require method?
I have met the same issue, what I have done was adding this be code below, prior loading my addon.
global.require = require;
I'm writing an application using NW.js and TypeScript. I would like to use one class per file.
To access node.js modules, I need to use require(). However, the document context within a require()d module is no longer the browser's document context.
It seems to me that I need to stick to namespaces to be able to access the browser DOM from my application.
How can I combine those two module styles in one TypeScript application? When trying to use namespace together with require, my types suddenly lose visibility across files (because the compiler goes into external module mode.)
It seems to me that I need to stick to namespaces to be able to access the browser DOM from my application
No. You can use a module loader like webpack to bundle the portions that the browser needs into a single bundle.js while still keeping all your code base in commonjs mode.
More
A quickstart is available : https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
More More
I am actually creating an OSS editor that demonstrates this : http://alm.tools/. The whole project (backend + server) has a single tsconfig.json file.
I am having difficulty resolving the electron modules in my web application using Electron v0.32.3 using require. My understanding (although its not very clear in the docs) is that the modules are supposed to be automatically available to require of the application being run in the webview (examples include 'ipc' and 'remote'). I can see that they are there at runtime, but I am not sure how to access them:
I feel like there is some piece to this that I am missing. Other information: my web application is a Durandal 2x SPA that uses require to load modules already. Is there any other kind of setup that is required in the render process requirejs config to access these modules?
It turns out I just didn't understand all of the different processes going on. So with an application that is using a webview inside of a browser-window, there are actually three processes to be concerned about:
Main process - has access to node
Renderer process (browser window) - has access to node by default
Web view process - does not have access to node by default
I was seeing the node modules available to 2) and trying to use them in 3). The webview has the 'nodeintegration' attribute that can be used to enable this:
http://electron.atom.io/docs/v0.34.0/api/web-view-tag/#nodeintegration
However, using a preload script allows for exposing only the necessary node functionality with using nodeintegration:
http://electron.atom.io/docs/v0.34.0/api/web-view-tag/#preload
I went with that solution, setting up communication between the renderer process and the webview process.
I setup a website with regular client side RequireJS today. Than I did some research on node, got that installed and setup my first module in node. When I setup the first require, I loaded the Require.JS file and I get all that. The thing that is confusing me is, I created a file called test.js and within that I am including:
var require = require("requirejs");
which is actually including the node require, not the original require library I was using right?
So like are they completely different? Can they used together?
Doesn't Node already have a module loader?
Yes Node does.
That loader uses the CommonJS module format. The
CommonJS module format is non-optimal for the browser, and I do not
agree with some of the trade-offs made in the CommonJS module format.
By using RequireJS on the server, you can use one format for all your
modules, whether they are running server side or in the browser. That
way you can preserve the speed benefits and easy debugging you get
with RequireJS in the browser, and not have to worry about extra
translation costs for moving between two formats. If you want to use
define() for your modules but still run them in Node without needing
to run RequireJS on the server, see the section below about using
amdefine.
Source: http://requirejs.org/docs/node.html#1