Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main entry point support #33

Open
sgentle opened this issue Dec 16, 2015 · 8 comments
Open

Main entry point support #33

sgentle opened this issue Dec 16, 2015 · 8 comments
Assignees

Comments

@sgentle
Copy link

sgentle commented Dec 16, 2015

I notice in your example webpack config you have { entry: './src/entry' }, which is a JS file that requires any PureScript modules that you need.

In my case, I just want to call Main.main, so mine looks like this: require('./Main.purs').main(); It seems like it would be cleaner if you could just use { entry: './src/Main.purs' } directly.

I believe the browserify/psc-bundle toolchain does something like this already. Would you consider adding it to purs-loader? I'm fairly new to PureScript, but happy to do the lifting with a bit of direction. (Though maybe #31 would make this irrelevant anyway.)

@ethul
Copy link
Owner

ethul commented Dec 18, 2015

Thanks for checking out the purs-loader. I agree it would be handy to use Main.purs as the entry directly. I will have to look into whether webpack supports something like this.

@ethul ethul self-assigned this Mar 12, 2016
@ethul
Copy link
Owner

ethul commented Nov 5, 2016

This does in fact work. See: ethul/purescript-webpack-example@923f3c1

@ethul ethul closed this as completed Nov 5, 2016
@Pauan
Copy link

Pauan commented Nov 6, 2016

@ethul I just tried building https://github.com/ethul/purescript-webpack-example but it didn't work:

/*!************************!*\
  !*** ./src/Entry.purs ***!
  \************************/
/***/ function(module, exports, __webpack_require__) {

// Generated by psc version 0.10.1
"use strict";
var $foreign = __webpack_require__(/*! ./src/Entry.js */ 1);
var Prelude = __webpack_require__(/*! ./bower_components/purescript-prelude/src/Prelude.purs */ 2);
var Control_Monad_Eff = __webpack_require__(/*! ./bower_components/purescript-eff/src/Control/Monad/Eff.purs */ 43);
var Control_Monad_Eff_Unsafe = __webpack_require__(/*! ./bower_components/purescript-eff/src/Control/Monad/Eff/Unsafe.purs */ 45);
var Example_Test = __webpack_require__(/*! ./src/Example/Test.purs */ 47);
var Example_Foo = __webpack_require__(/*! ./src/Example/Foo.purs */ 49);
var Example_Foo_Baz = __webpack_require__(/*! ./src/Example/Foo/Baz.purs */ 53);
var result = Control_Monad_Eff_Unsafe.unsafePerformEff($foreign.hot);
module.exports = {
    result: result, 
    hot: $foreign.hot
};
//# sourceMappingURL=index.js.map

Notice that it does not call anything, therefore it does nothing when running node bundle.js

The point of this issue is to automatically call the main Eff from the Main module, just like when using psc-bundle --main Main

@ethul
Copy link
Owner

ethul commented Nov 6, 2016

Agreed. You're totally correct. I was too soon on closing this. I've been updating the example further. Please see: https://github.com/ethul/purescript-webpack-example/blob/30265626f89b605bf24be94a8f7fadd2610bcd23/src/Example.purs#L17-L25

@Pauan
Copy link

Pauan commented Nov 6, 2016

@ethul With psc-bundle, it is not necessary to use unsafePerformEff, instead you simply return an Eff from main, which is idiomatic in PureScript.

I think purs-loader should support a main option, similar to psc-bundle

@Pauan
Copy link

Pauan commented Nov 6, 2016

@ethul Hm, actually, I thought about it some more. Webpack supports multiple entry points, so you would really want to be able to specify a different main per entry point. That complicates things a lot.

If you only have a single entry point, you can currently use the following to specify the main:

module: {
  loaders: [
    {
      test: /\.purs$/,
      loader: "purs-loader",
      exclude: /node_modules/,
      query: {
        bundle: true,
        pscBundleArgs: {
          main: "Main"
        },
        src: ["bower_components/purescript-*/src/**/*.purs", "src/**/*.purs"]
      }
    }
  ]
}

@ethul
Copy link
Owner

ethul commented Nov 6, 2016

Right. So you can return an Eff instead of performing the IO, but I am unsure how webpack would know to run this.

Maybe the loader could create a wrapper entry module that invokes this function. Supporting a main for each entry could maybe be done in a similar way if the loader was able to know which modules are "entry modules" then it can wrap each of the entries, and we'd need a configuration that we can lookup the right main function using the module name (as one idea).

E.g.,

{
  moduleMainFunctions: {
    'ExampleEntry1': 'example1',
    'ExampleEntry2': 'example2'
  }
}

@ethul
Copy link
Owner

ethul commented Mar 21, 2017

@saevarb Thanks for your feedback.

Does your issue relate to #33 or are you describing a new issue?

If you are able to provide a little more explanation on how your issue fits into with #33, I'll be better able to investigate this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants