moonscript-loader
is a webpack4 loader for compiling MoonScript to Lua.
It is intended to be used with fengari.io/fengari-loader (but if you find another way to run Lua go ahead).
This is just an example setup - webpack is very flexible. Don't assume any of these extra dependencies are necessary.
install dependencies:
touch package.json && npm i --save-dev webpack webpack-dev-server fengari-loader fengari-web moonscript-loader html-webpack-plugin
set up your webpack config (webpack.config.js
):
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
context: __dirname,
entry: './toast.moon',
mode: 'development',
module: {
rules: [
{
test: /\.moon$/,
use: [
'fengari-loader',
'moonscript-loader',
]
},
]
},
plugins: [
new HtmlWebpackPlugin(),
],
}
write some Moonscript (toast.moon
):
window = js.global
y = (x) -> x * 2
window.console\log y 14
run everything and visit http://localhost:8080 :)
node_modules/.bin/webpack-dev-server -w