https://github.com/double-oxygen/nim-loader
A Webpack loader for the Nim language
https://github.com/double-oxygen/nim-loader
nim nim-lang webpack webpack-loader
Last synced: about 1 month ago
JSON representation
A Webpack loader for the Nim language
- Host: GitHub
- URL: https://github.com/double-oxygen/nim-loader
- Owner: Double-oxygeN
- Created: 2018-12-05T23:53:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-11T05:01:34.000Z (over 2 years ago)
- Last Synced: 2025-03-18T14:53:40.207Z (2 months ago)
- Topics: nim, nim-lang, webpack, webpack-loader
- Language: JavaScript
- Homepage:
- Size: 688 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nim-loader
A [Webpack][webpack-home] loader for the [Nim][nim-home] language.
## How do I use it?
First of all, make sure that you have [Nim installed][nim-installation].
Then install [nim-loader]:```sh
npm install nim-loader
```Next, configure your `webpack.config.js` to use this loader:
```js
module: {
...
rules: [
...
{
test: /\.nim$/,
use: [
{
loader: 'nim-loader',
options: {
flags: ['--nim-compiler-flags']
}
}
]
}
...
]
...
}
```Of course, `options` is optional. If you don't want advanced behavior you can
use the terse syntax:```js
module: {
...
rules: [
...
{
test: /\.nim$/,
loader: 'nim-loader'
}
...
]
...
}
```Finally, `import` your Nim file from your Javascript code.
```js
import nimModule from './path/to/nim/file/module.nim'
nimModules.exportedFunction("With arguments")
```## Caveats
While Nim has native concepts of exporting functions and modules, these do not
translate to the Javascript compile target. Instead, you are encouraged to use
CommonJS module exports. This requires that your Nim code "imports" the `module` object. Doing so looks like this:```nim
import jsffi
var module {. importc, nodecl .}: JsObject
...
module.exports = exportObject
```where `exportObject` is of type `JsObject`. Note that `modules.exports` is
already initialized to an empty object, so you can also do something like:```nim
...
module.exports.someFunction = functionImpl
module.exports.someValue = nimValue
...
```to register your exports one-by-one.
## Examples
If you're still confused, hopefully the [examples][nim-loader-demo] can help.
[webpack-home]: https://webpack.js.org/
[nim-home]: https://nim-lang.org/
[nim-installation]: https://nim-lang.org/install.html
[nim-loader]: https://github.com/bmollot/nim-loader
[nim-loader-demo]: https://github.com/bmollot/nim-loader-demo