stealjs / steal-conditional

Conditional loading
https://stealjs.com/docs/steal-conditional.html
MIT License
6 stars 1 forks source link

steal-conditional boolean throw an error #42

Closed matthewp closed 7 years ago

matthewp commented 7 years ago

@pYr0x commented on Tue May 16 2017

i used the steal-conditional boolean syntax to load a module. require("~/modules/notice-box#?triwala-vk/modules/notice-box-exists");

reduce the notice-box-exists to the basic the module looks like this:

import $ from 'jquery';
const foo = false;
export default foo;

when i create a production version i get this error image the problem is "jquery" but i dont know why. @m-mujica any idea why jquery cause an error in steal-conditional if i import a module that does not use jquery i works. import '~/util/url'; url.js

exports.setLocation = function (url) {
    var htmlDoc = document.getElementsByTagName('html')[0];
    htmlDoc.classList.add('wait');
    window.location.href = url;
    return false;
};

@pYr0x commented on Tue May 16 2017

i found out that module.exports = !!window.document.querySelector('.notice-box'); is not working too.

window is not defined. is the problem that while build, the loader is using node and there is not window object present?


@m-mujica commented on Tue May 16 2017

@pYr0x are you using the latest version of steal-conditional?

steal-conditional should not eval your condition module (notice-box-exists) during the build

See https://github.com/stealjs/steal-conditional/blob/68283fd641bf97aa969946576fd6c4a05ae0d1cc/conditional.js#L323-L327

I'll try to replicate the jquery issue.


@m-mujica commented on Tue May 16 2017

@pYr0x in this case, since you're using the boolean syntax, steal-conditional should make a bundle of ~/modules/notice-box. https://github.com/stealjs/steal-conditional/blob/68283fd641bf97aa969946576fd6c4a05ae0d1cc/conditional.js#L259


@pYr0x commented on Tue May 16 2017

@m-mujica i used "steal-conditional": "^0.3.2" notice-box is bundled into a file called index-form-index-bd4d57f2.js and notice-box-exists is also bundled into a file

/*triwala-vk@1.0.0#modules/notice-box-exists*/
define('triwala-vk@1.0.0#modules/notice-box-exists', function (require, exports, module) {
    const loader = require('@loader');
    let ex = false;
    if (loader.isPlatform('window')) {
        ex = !!document.querySelector('.notice-box');
    }
    module.exports = ex;
});

and if i use a console.log in the module notice-box-exists the output is shown during the build. so the module will be eval during build

pYr0x commented 7 years ago

@m-mujica any plan of fixing this bug? do you need a example app?

m-mujica commented 7 years ago

@pYr0x I haven't looked at this. I'll try to get some time before end of week to fix it. I'll let you know if I run into issues replicating the bug.

m-mujica commented 7 years ago

@pYr0x I just published steal-conditional@0.3.5 with the fix, I did a small example to replicate your issue and it build correctly with 0.3.5

Please give it a try when you have some time and let me know if you run into any issue.