Haxe nodejs split js, insted of one js - node.js

How can I generate separated js files, when use Haxe nodejs target?
Now I have one big js file, but I wanted to compile each class to separated js files.
I found modular-js, but if I think good, this is not work for nodejs (because AMD), just for frontend js.
thanks

Have you seen hxgenjs? It claims to support Node.js:
The default configuration emits one javascript file per Haxe class, and uses CommonJS (require()) to link the dependencies. It should work out of the box with your current Node.js project, React Native project or any other CommonJS-compatible runtimes.

Related

How do I package node.js app into single file (without bundling node.js itself)?

I'm looking for a way to deliver a node.js server-side application (not browser) as a single file that contains all my code and node_modules. Well, it can be a few files, but I'd like to avoid shipping 10,000+ files, that are usually in node_modules.
I've used solutions like pkg, but I don't need an executable that has node.js bundled. I'd rather ship node.js separately and only have a bundle with code. This would be especially useful as I need to ship a few applications and don't need each of them to contain a copy of node.js.
Appreciate any suggestions.

Reference compiled React javascript from Nodejs server

I have a React app that renders markup based on user input and I need to be able to render the markup the same way without a client. I've seen other people accomplish this by using Nodejs, is it possible to access React Components from Node given a reference to a compiled and minified Javascript file (this file is my React code bundled).
Yes, that is certainly possible with something like reactDOMServer. You can read more at: https://reactjs.org/docs/react-dom-server.html
What are you trying to do exactly? Are you trying to do it on a server? Or just on a command line? Are you using any bundlers like Webpack or Parcel?

Angular2 deploying to production environment questions

Some questions to put angular2 web project to production environment
We do development on lite server but what is best for production? Is is some other server module of nodejs? Technically we can have any server (apache, tomcat, etc).
How should we do source code management for below context.
browser must include js files so project should have js files when deployed
In standard java project we just commit .java files and uses jenkins (may be other tools) to compile and make the deploy-able structure
Should we follow same strategy here? i.e. don't commit compiled js files and deploy using some node compiler which takes ts files and compiles it to js
What is the best way to minify/obfuscate the js files
I know a way using outDir and outFile with grump but I don't want every files tobe included in one minified file because it kills the concept of lazy loading
Is there a way to minify and obfuscate js files on compile time only?
What enableProdMode() do? How it is different than not using it?
Here are some answers to your questions:
Angular2 applications only consist of static files so they can be serve by any static Web servers or server applications that can define static folders (Express, ...)
Regarding source code management, you must have a packaging phase to optimize the application loading (gater files, uglify, ...). Your source code must contain your TypeScript files (or JS files if using ES5 or ES6). Such packaging can be done using Gulp for example. Your Jenkins server will be able to checkout the source code, build it and execute tests.
In fact, when not using the outFile property of the TypeScript compiler, you won't be able to gather all the JS compiled files into a single one since anonymous modules will be created within each JS files.
See this question for more details of this:
How do I actually deploy an Angular 2 + Typescript + systemjs app?
Regarding prod mode, here is an extract of the documentation:
Disable Angular's development mode, which turns off assertions and other checks within the framework.
One important assertion this disables verifies that a change detection pass does not result in additional changes to any bindings (also known as unidirectional data flow).

Minify javascript files with Node JS

We are using node js to minify javascript files in one single file. I want to know if there is a way to specify the order of the js files to be minified. Why? because we are using jquery-ui and moment datepicker. These two libraries are using a function that has the same name (datepicker). We are able to manage on the development environment to load first jquery-ui and after moment datepicker because we need the one on the moment datepicker file, so loading the files on this way, everything is good but when we end up on the deploying using Node JS, the jquery-ui comes at the end and overrides the moment datepicker and the datepicker is not working as expected. We are also using require js in our project. Any idea would be much appreciated.

Sharing code between node js project and a web site project

So I started coding a chess engine in typescript as a side project. I initially intended it to be a CLI like most other chess engines that interact through stdin and stdout. This so I could plug it to a GUI like Arena and test it against other engines. For that I decided to do it as a node project.
I set it across several files with 1 being the UCI (universal chess interface) implementation and the remaining ones chess logic and AI logic. After banging my head a few times trying to understand modules in typescript I finally got it to work.
Now I decided it would be interesting to write a simple GUI myself as a webpage with html+typescript+jquery. Now, I would like to use all the logic modules I wrote but I'm finding it impossible. From what I understand you can't use CommonJS in browsers so the only way I could get it to work was using instead internal modules for which I need to modify the .ts files to wrap the code in module X{ } blocks and recompile them just for the GUI every time I change something. This situation seems far from ideal and I was wondering if there is a way around it...
Use http://browserify.org/ to add CommonJS-like support on the front-end.
But also read this (slightly outdated) question and answer: How should I go about writing a node.js web application with both server and client side code?
Use external modules for both the server and the browser.
When compiling for the browser, use the switch to specify the AMD module pattern:
tsc --module amd app.ts
And use RequireJS to load modules for you.
<script src="require.js" data-main="app.js"></script>
You will need to compile for the different targets, but the source code in TypeScript can be identical.
I created a demo project to share code between the client and the server : https://github.com/basarat/demo-fullstack/blob/master/src/Gruntfile.js
It compiles the common files for both amd/commonjs and server files only as commonjs with the client only files as only amd. It uses grunt-ts to manage this : https://github.com/grunt-ts/grunt-ts

Resources