https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • m

    mysterious-toddler-20573

    08/10/2020, 4:21 PM
    my javascript build-fu is terrible
  • m

    mysterious-toddler-20573

    08/10/2020, 4:22 PM
    are you any good at it?
  • m

    mysterious-toddler-20573

    08/10/2020, 4:22 PM
    I want to keep htmx really simple single-file, and build-tool agnostic, but there are a of different standards
  • m

    mysterious-toddler-20573

    08/10/2020, 4:22 PM
    :/
  • s

    salmon-truck-9425

    08/10/2020, 4:52 PM
    no to be honest i am not. however i can code a sample minimum project with webpack maybe this evening or tomorrow so someone could take a look.
  • m

    mysterious-toddler-20573

    08/10/2020, 4:52 PM
    OK
  • m

    mysterious-toddler-20573

    08/10/2020, 4:52 PM
    sounds good, sorry
  • m

    mysterious-toddler-20573

    08/10/2020, 4:52 PM
    I have been avoiding javascript build tools for a decade now
  • b

    big-airline-13935

    08/10/2020, 6:40 PM
    I'm sure @User could weigh in re webpack.
  • w

    wooden-wall-85896

    08/10/2020, 6:42 PM
    @User So you're saying that you've bundled up htmx with webpack, and loading it via dynamic import then causes it to not work?
  • s

    salmon-truck-9425

    08/10/2020, 7:49 PM
    @User yes
  • s

    salmon-truck-9425

    08/10/2020, 7:50 PM
    actually; its bundled with the main.js file already. The dynamic import can contain some other javascript code
  • s

    salmon-truck-9425

    08/10/2020, 7:50 PM
    But if the dynamic import is invoked, htmx doesn't work for some reason; as if no events are registered etc
  • s

    salmon-truck-9425

    08/10/2020, 7:51 PM
    i am actually writing a simple index.html/webpack config to try to reproduce it
  • b

    big-airline-13935

    08/10/2020, 7:52 PM
    @User Even if the dynamic import doesn't do anything besides a
    console.log
    ?
  • s

    salmon-truck-9425

    08/10/2020, 7:52 PM
    @User yes, it can even be an empty js file
  • b

    big-airline-13935

    08/10/2020, 7:53 PM
    Can you clarify how you're importing htmx, via dynamic import or the main file?
  • s

    salmon-truck-9425

    08/10/2020, 7:55 PM
    in main.js file; like so:
    Copy code
    import "htmx.org"
    
    var Routes = {
     '/somepage': () => import('somepage.js'); //somepage.js is an empty js file.
    };
    
    document.addEventListener("DOMContentLoaded", function() {
        var currentRoute = document.body.getAttribute("data-page-route"); //this will be /somepage
        if (currentRoute in Routes) {
            Routes[currentRoute]().then((m) => {
                // this loads somepage.js which is an empty file
                console.log('loaded script for ${currentRoute}');
            });
        }
    });
  • w

    wooden-wall-85896

    08/10/2020, 8:03 PM
    So probably @User you'll need to manually call some entrypoint to execute the htmx code
  • w

    wooden-wall-85896

    08/10/2020, 8:03 PM
    When you load legacy JS as ES modules, you generally need to shim them in some way to execute the "init" or whatever method that normally runs automatically
  • w

    wooden-wall-85896

    08/10/2020, 8:04 PM
    I'd need to look at the htmx code more to do more with it
  • b

    big-airline-13935

    08/10/2020, 8:10 PM
    I believe htmx simply uses a self executing function to initialise itself.
  • b

    big-airline-13935

    08/10/2020, 8:12 PM
    Which then executes the
    ready
    function: https://github.com/bigskysoftware/htmx/blob/dev/src/htmx.js#L1663-L1669
  • w

    wooden-wall-85896

    08/10/2020, 8:22 PM
    Probably you'd need to add a manual trigger or fake "ready" because if the script is async loaded in, it could be loaded in at any time
  • w

    wooden-wall-85896

    08/10/2020, 9:10 PM
    @User -> https://webpack.js.org/guides/shimming/
  • t

    tall-dinner-62086

    08/11/2020, 10:50 AM
    When I load new elements through htmx into a page, is there a way to initialize only those elements for hyperscript? If I call
    _hypserscript.start()
    it duplicates event listeners on existing elements.
  • m

    mysterious-toddler-20573

    08/11/2020, 1:13 PM
    @User you shouldn't need to call it on new elements
  • m

    mysterious-toddler-20573

    08/11/2020, 1:14 PM
    https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L936
  • s

    salmon-truck-9425

    08/13/2020, 9:31 AM
    just FYI, for my usecase at least for webpack I managed to get it to work by: a) removing the ready(callback) call from here: https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L1699 b) adding the code present in the ready callback as part of a public api returned from htmx as an "initialize" function c) calling it like so:
    Copy code
    document.addEventListener("DOMContentLoaded", function () { 
        var currentRoute = document.body.getAttribute("data-page-route");
        if (currentRoute in Routes) {
            Routes[currentRoute]().then((m) => {
                htmx.initialize();
            });
        }
    });
    why does this need special treatment for webpack? i don't know - it works under rollup. But then rollup blows for rest of my code... to summarize YUCK all the webpack/rollup w/e build tools - incosistent blackboxes that do nothing but waste time ; (
  • m

    mysterious-toddler-20573

    08/13/2020, 2:04 PM
    whyIMadeHtmxNotRequireAnyJavascriptBuildTools.txt
1...141516...1146Latest