【发布时间】:2018-04-14 00:41:11
【问题描述】:
我设置了使用 elm-static-html-lib 生成 html 的 javascript,这需要从我的 elm 代码中传入视图、模型和 json 解码器。
当我尝试使用节点运行 javascript 时,我收到以下错误消息:“找不到包 mdgriffith/style-elements。”
我设置 javascript 的方式几乎与 elm-static-html-lib 的 github 页面的第一个示例中的设置方式完全相同:https://github.com/eeue56/elm-static-html-lib
有人知道为什么会这样吗?
这似乎是我正在使用的方法的问题,因为当我切换到使用 Html.program 创建视图时,我没有收到任何依赖关系错误。而且我已经尝试删除 elm-stuff/ 并重新构建,但这并不能解决问题。
这里是JS代码:
const esh = require("./node_modules/elm-static-html-lib/dist/index.js");
const fs = require('fs');
const model = { name: "Noah", age : 24 };
//const model = require('./index-new.json'); //with path
const options = { model : model, decoder: "Main.decodeModel", alreadyRun: false };
function generateHtml() {
esh.default(process.cwd(), "Main.view", options)
.then((generatedHtml) => {
fs.writeFileSync("output.html", generatedHtml);
});
}
generateHtml();
还有我的 Main.elm 模块
module Main exposing (..)
import Html exposing (Html)
import Json.Decode exposing (..)
import Element exposing (..)
import Element.Attributes exposing (percent, width, spacing)
import Element.Events exposing (..)
import Style exposing (..)
-- MODEL
type alias Model =
{ age : Int
, name : String
}
type Style
= None
type Variation
= Selected
decodeModel : Json.Decode.Decoder Model
decodeModel =
Json.Decode.map2 Model
(Json.Decode.field "age" Json.Decode.int)
(Json.Decode.field "name" Json.Decode.string)
-- VIEW
view : Model -> Element Style variation msg
view model =
column None [] [text "Hello"]
stylesheet : StyleSheet Style Variation
stylesheet =
Style.styleSheet
[ style None [] ]
【问题讨论】:
标签: javascript html json package elm