如何用Dune将index.html复制到编译后JS文件所在的_build目录?
解决Dune将index.html复制到_build目录的问题
项目目录结构
. ├── bin │ ├── counter.ml │ ├── dune │ └── index.html ├── dune-project └── fmlib_tutorial.opam
当前bin/dune内容
(executable (name counter) (modules counter) (modes js) ; 启用JavaScript编译 (libraries fmlib_browser) ; 使用该库 ) (rule (targets counter.js) ; 生成文件'counter.js' (deps counter.bc.js) (mode (promote (until-clean))) (action (copy counter.bc.js counter.js)) )
解决方案
在bin/dune文件中添加一条复制index.html的规则,修改后的完整内容如下:
(executable (name counter) (modules counter) (modes js) ; 启用JavaScript编译 (libraries fmlib_browser) ; 使用该库 ) (rule (targets counter.js) ; 生成文件'counter.js' (deps counter.bc.js) (mode (promote (until-clean))) (action (copy counter.bc.js counter.js)) ) (rule (targets index.html) (deps ./index.html) (action (copy %{deps} %{targets})) )
规则说明
(targets index.html):指定目标文件为index.html,Dune会将其生成在当前目录对应的_build路径下(即_build/default/bin/,与编译后的JS文件同目录)(deps ./index.html):声明依赖为当前源码目录下的index.html文件(action (copy %{deps} %{targets})):执行复制操作,将依赖的源码文件复制到目标位置
执行dune build后,即可在_build/default/bin/目录下看到index.html、counter.bc.js和counter.js三个文件。
内容的提问来源于stack exchange,提问作者ixb
相关产品推荐
相关产品推荐

