It would be nice if one can run node.js code inside Excel user-defined functions. Something like using js code like VBA.
I googled for solutions but cannot find any. Is it possible to do this?
Yes, if you want to use packages from NPM. You could use webpack to combine all the stuff to one js file, it should work.
webpack as a static module bundler for modern JavaScript applications. When webpack processes your application, it internally builds a dependency graph which maps every module your project needs and generates one or more bundles. you could refers to this document.
You could also refer to a sample, Yeoman, the Yeoman generator creates a Node.js Office Add-in project. it use webpack combine all files into one js file.
Related
So I've created a simple program using node.js and a couple of libraries using puppeteer and kijiji-scraper from npm and I want to run it on a webpage like Github pages. In the past, I've had success using a CDN to import the node library I needed to do so by following the instructions on the readme. But for these packages, there aren't any instructions for importing using CDN. Is it just not possible to do so or am I missing something?
Packages:
https://www.jsdelivr.com/package/npm/kijiji-scraper
https://www.npmjs.com/package/puppeteer
NodeJS and the web have fundamentally different moduling systems. You won't be able to import libraries written for Node in the web. If the libraries are pure JavaScript libraries (not relying on the standard library or native modules) or are browser-based libraries relying on the DOM, then you can use Browserify to compile the library's source code into a single file and include that on the web page with a <script>. Otherwise, you'll need to restructure your application around this limitation.
In your case however, it looks like Kijiji is a client-side library and Browserify will be your solution here.
You can come to this conclusion by skimming some of its source code. You'll notice that there's a require call in it. The require function doesn't exist on the DOM API and hence will throw the error you're getting.
The solution I would use in your case would be a) Grunt or Gulp or b) compiling the code and import them statically.
If you have a more complex build chain, I would suggest including the browserify stage in it. I would also not use the CDN based library, rather use the NPM library. The browserify stage will bundle the library and all required dependencies into a single file that can be used in HTML
<script src="/static/kijiji.js"></script>
<script src="/app/index.js"></script>
I'm not sure what your file structure looks like but you get the idea.
I am currently developing a Typescript application using lit html. I have reached the point where I want to bundle all my typescript files, minimize them in to a single javascript file. Using VS Code as the IDE.
I have been looking at options - rollup.js is one option but I couldn't work out how to bundle multiple ts files in to a single js file, minimize it and also ensure the modules are handled correctly.
Any examples of using rollup.js to do such available or another alternative available?
You can use Parcel js for this as well. This will generate one js file. but if you require rollup js, may be this link will help you out.
Generate typescript definition files using rollup
I'm working on an application using typescript. The code of my app is designed as follows:
Solution's Explorer
I've two questions:
How to build one .js file per module? Today I've one project per module, so the VS2013 build one .js file per module but I don't know if this approach is the best available.
How to reference the modules on the GlobalAppModule, if I put the references in TypeScript directly, VS2013 build the code of one module in another's.
My original idea was to have only one project in my solution and create a build script to build which module to his own .js file.
The compiler should output one JavaScript file for each input TypeScript source file. If you are seeing all your TypeScript source get combined into one JavaScript file per project, could you please check the project properties, and on the "TypeScript Build" tab ensure that "Combine JavaScript output into file" is not checked (this maps to the "--out" command-line parameter).
To reference files across projects, you can either:
Reference the code directly via "/// " tags. This will however pull that referenced code into the compilation, which may not be desirable across projects.
Choose to "Generate declaration files" for the build of the project to reference ("--declaration" on the command-line). This will create a "*.d.ts" file describing the types in the project. You can then reference this declaration file in the other project (which will cause all the types to appear and be accessible, but won't pull in the actual source from the other project).
I hope this helps.
In Node.js, you can dynamically "require()" any javascript file likewise to PHP's require. I'd like to use this in my client-side code just for ease of development but not actually call a javascript function, but have a compiler replace the line with the contents of the respective file; effectively concatenating the files, not one after another, but inline within the code of one of the files. The closest thing I have found to this is smash. Are there any compilers, minifiers, etc that can do this?
Browserify might not be exactly what you want but it does definitely help with the ease of development issue. When you use Browserify, your code is your build tool. Browserify gives you all the benefits of writing code in node (no anon functions to avoid globals, npm, simple requires, imports instead of namespaced globals) and it allows you to package that code to run on the client with one command and only load one file.
You can checkout my open source js framework Luc JS for an example. It runs on node and IE6. I'm able keep the code modular and build the single browser file with a one line command.
I'd like to start bundling our javascript files. I've found that it's really easy locally using the web essentials plugin, however I need to set up the build server to generate the bundled .js file.
I'd rather not check this generated file into TFS as it will cause conflicts for our developers, and also since it's generated from the source I feel that the server build should generate it.
Is there a command line utility for doing the script bundling outside of visual studio that could be used as part of a build script? My google-fu is failing to find one.
Many thanks,
As long as you wrote it as proper AMD modules, require.js comes with a tool to turn all your files into an optimized bundle.