madsflensted / elm-brunch

Brunch plugin to compile Elm code
MIT License
74 stars 31 forks source link

Can't compile Elm file #48

Closed mickeyvip closed 5 years ago

mickeyvip commented 5 years ago

Problem

image

Information

mickeyvip commented 5 years ago

Found 1 of my problems - mainModules should be an array.

Now the file compiles:

image

But when requiring it - it gets only an empty object:

image

madsflensted commented 5 years ago

Good to hear that you solved the compilation problem. Beware that the elm brunch plugin does not pass the generated code on down the brunch pipeline, as other to-js-transpilers do. So you will need to either include the generated js in your html use other means to get it into the main bundle.

mickeyvip commented 5 years ago

@madsflensted , thank you.

Following your advice, I have added <script src="js/main.js"></script> to the index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Simple Brunch Demo</title>
    <link rel="stylesheet" href="app.css" />
  </head>

  <body>
    <main id="root"></main>
    <h1>
      Brunch
      <small>• A simple demo</small>
    </h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
    <script src="libraries.js"></script>
    <script src="js/main.js"></script>
    <script src="app.js"></script>
    <script>
      require('application').init();
    </script>
  </body>
</html>

removed the const Elm = require('./elm/Main.elm'); from the application.js.

'use strict';
const Greeter = require('./greeter');
const App = {
  init() {
    console.log('App initialized.');
    const g = new Greeter();
    g.greet();
    Elm.Main.init({ node: document.getElementById('root') });
  },
};

module.exports = App;

and now it is working:

image

mickeyvip commented 5 years ago

Maybe it's worth to mention this in the docs? Or did I miss this?