node-swift
node-swift copied to clipboard
Webpack loader plugin for importing .swift files directly
This would be a nice to have:
example.swift:
import Foundation
import NodeAPI
@main struct MyExample: NodeModule {
let exports: NodeValueConvertible
init() throws {
exports = [
"getTime": try NodeFunction { _ in
Date().timeIntervalSince1970.rounded(.down)
}
]
}
}
index.js:
const { getTime } = require("./example.swift");
console.log(`Seconds since 1970: ${getTime()}`);
// Seconds since 1970: 1647672663
webpack.config.js:
module.exports = {
module: {
rules: [
{
test: /\.swift$/i,
use: ["node-swift-loader"],
},
],
},
};