jasononeil/webpack-haxe-loader

custom haxe path

francescoagati opened this issue · 9 comments

hi,
is possible use a custom path for the haxe compiler in the webpack config?

It currently uses haxe from the PATH.

An option could be added but then it is user/platform specific so the config isn't the right place for that. Haxe doesn't suggest a standard way to handle that.

@jasononeil has started looking into using Haxe from npm - that makes it crossplatform. We should use it if it's specified in the package.json.

thanks

The other problem of using Haxe from npm is that we need to use haxelib from npm - quite a serious change of workflow.

yes can be a big change. maybe the custom path can be another idea?

Maybe support a user "rc" file, but we'd like to stick to something relatively standard...

(also maybe I'm wrong about the requirement to use haxelib from npm)

@elsassph @francescoagati I've been thinking about this some more, and the two tools I know of to load Haxe through NPM are https://yarnpkg.com/en/package/haxe and https://yarnpkg.com/en/package/haxeshim

Both of these install the "binaries" to node_modules/.bin/haxe and node_modules/.bin/haxelib, and both of them handle the path between haxe and haxelib. (Well, haxeshim pretty much removes the need for haxelib, but you get my point).

So theoretically we could just change the loader to detect if haxe is available in node_modules/.bin/haxe, and if it is, use the local haxe rather than global haxe.

We could make it configurable as a string (take any path), as a "preferLocal" or "preferGlobal" boolean flag, or just have default behaviour to prefer local if available.

What do you think about that approach?

i think that the haxe path can be simple passed as parameter of haxe loader in the webpack config.
we need only expose this part as a parameter https://github.com/jasononeil/webpack-haxe-loader/blob/master/index.js#L34

I've just realised that any haxe installation used via NPM (so either https://www.npmjs.com/package/haxe or https://www.npmjs.com/package/haxeshim) will install to node_modules/.bin/haxe, and by default both npm run webpack and yarn webpack will have this on the path.

What this means is that you can be in an environment without haxe installed (or with an existing, incorrect version of haxe installed), and it will install a local haxe as part of installing NPM dependencies, and use that during the webpack build, with no extra change to the code necessary.

I'll leave this issue open and mark it as "help wanted", because I think it's still worth having a configurable option, but at least using NPM packages is a suitable path forward for now.