Git Product home page Git Product logo

Comments (13)

rrdelaney avatar rrdelaney commented on May 27, 2024

I recommend using a separate modules directory when requiring non-bucklescript files. See the documentation on resolve.modules. This lets you still require JS files, just not co-located with your Reason or OCaml files.

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

Hm this issue is about bs files only, I actually used files from your example.

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

I'll try to elaborate.

This is src from the example:

| -- src/
     |-- fib.re
     |-- print.re
/* print.re */
Js.log (Fib.fib 10);

^ This what loader receives. Internally loader passes it to bsb and it compiles it to:

...
var Fib = require('./fib.js');
...

This output as a string is passed from loader to webpack, but webpack is dealing w/ src/print.re and looking for './fib.js' in src folder (it expectsfib.js to be right next to src/print.re, not to lib/js/src/print.js).

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

Can you please paste your webpack config and bucklescript config?

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

Sure, here is the repo to reproduce: https://github.com/alexfedoseev/bs-loader-issue

Output:

screen shot 2017-04-24 at 13 55 32

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

Looks like the newer version of Bucklescript broke this! I was using 1.5 on my example, but as soon as I installed 1.7 it started to repro your issue. I'll look further into this now that I know what the problem is.

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

Looks like the problem was created in the Bucklescript 1.6.1 release with this issue: rescript-lang/rescript-compiler#1465. I'll try to look more into this when I get the time, but the fix will probably be on the Bucklescript side.

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

Looks like with 1.5 when webpack receives require('./foo'), it resolves src/foo.re and it most likely causes double compilation work as src/foo.re was already compiled by bsb when it dealt w/ src/app.re. It might be significant overhead w/ big dependency tree.

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

The double compilation overhead was pretty small when I was first testing this, bsb seemed to cache pretty well. Haven't done it with a large codebase though.

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

Good to know! I also tried to switch the context of the file inside the loader so webpack can resolve already compiled files, but looks like webpack doesn't allow this. And most likely it will cause issues w/ watch mode.

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

I make a pretty hacky fix in b815752 and published version 1.2 to npm. Can you see if that works for you?

from bs-loader.

alex35mil avatar alex35mil commented on May 27, 2024

Works, thanks! Should I close this?

from bs-loader.

rrdelaney avatar rrdelaney commented on May 27, 2024

Yep, re-open it if 1.2 is buggy for whatever reason!

from bs-loader.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.