Lumo 开源项目使用教程
1. 项目的目录结构及介绍
Lumo 项目的目录结构如下:
lumo/
├── bin/
├── build/
├── docs/
├── scripts/
├── src/
│ ├── api/
│ ├── cli/
│ ├── common/
│ ├── compiler/
│ ├── repl/
│ ├── runner/
│ └── main.cljs
├── test/
├── .gitignore
├── .npmignore
├── LICENSE
├── package.json
├── README.md
└── webpack.config.js
目录介绍
bin/
: 包含可执行文件。build/
: 包含构建生成的文件。docs/
: 包含项目文档。scripts/
: 包含构建和部署脚本。src/
: 包含源代码文件。api/
: 包含 API 相关的代码。cli/
: 包含命令行接口相关的代码。common/
: 包含通用模块代码。compiler/
: 包含编译器相关的代码。repl/
: 包含 REPL 相关的代码。runner/
: 包含运行时相关的代码。main.cljs
: 项目的主入口文件。
test/
: 包含测试文件。.gitignore
: Git 忽略文件配置。.npmignore
: npm 忽略文件配置。LICENSE
: 项目许可证。package.json
: npm 包配置文件。README.md
: 项目说明文档。webpack.config.js
: Webpack 配置文件。
2. 项目的启动文件介绍
项目的主入口文件是 src/main.cljs
。这个文件负责初始化项目并启动应用程序。以下是 main.cljs
的主要内容:
(ns lumo.main
(:require [lumo.repl :as repl]
[lumo.compiler :as compiler]
[lumo.runner :as runner]))
(defn -main [& args]
(println "Starting Lumo...")
(repl/start)
(compiler/init)
(runner/run args))
(set! *main-cli-fn* -main)
启动文件介绍
lumo.main
: 命名空间定义。-main
: 主函数,负责启动 REPL、初始化编译器并运行应用程序。*main-cli-fn*
: 设置主函数为-main
。
3. 项目的配置文件介绍
项目的配置文件主要包括 package.json
和 webpack.config.js
。
package.json
package.json
文件定义了项目的元数据和依赖项。以下是部分内容:
{
"name": "lumo",
"version": "1.0.0",
"description": "Fast, cross-platform, standalone ClojureScript environment",
"main": "src/main.cljs",
"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"clojurescript",
"lumo",
"repl"
],
"author": "Antonio Monteiro",
"license": "MIT",
"dependencies": {
"clojure": "^1.8.0",
"lumo-cljs": "^1.0.0"
},
"devDependencies": {
"webpack": "^4.0.0"
}
}
webpack.config.js
webpack.config.js
文件定义了 Webpack 的构建配置。以下是部分内容:
const path = require('path');
module.exports = {
entry: './src/main.cljs',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.cljs$/,
use: 'clojurescript-loader'
}
]
},
resolve: {