stealjs / steal-tools

Build easy. Load fast.

Home Page:https://stealjs.com/docs/steal-tools.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

 appearing in html when using `deps-bundle`

eben-roux opened this issue · comments

commented

It seems as though the bundling option adds a BOM character of sorts when merging files. While using the deps-bundle option on my samples repository I noticed the character in my html since my spacing seemed a bit off.

I use a postinstall script as follows:

"postinstall": "steal-tools bundle --deps"

commented

I think I found the BOM issue.

In the steal loader-sans-promises.js file I replaced line 2171 with resolve(source.replace(/^\uFEFF/, ''));:

image

Perhaps someone can confirm this; else I can submit a PR in due course.

There are BOM stripping modules but I used the above code from this SO answer since it is a rather simple/short fix.

What is the load.address when you do this? I think the answer is to avoid adding the BOM in the first place.

commented

That does sound like a reasonable approach. I haven't looked at this for a while so I'll have to get back to you on the load.address. I have set my IDE (WebStorm) to not add the BOM so it rather odd and it seems to appear only when merging and not when using the individual files.

commented

I ran into this issue again in a production build. It turns out that the offending files are my own (who would've thunk it?). I don't know why WebStorm added the BOM. I am using VSCode nowadays so perhaps it is keeping the BOM when it is present.

I agree that trying to avoid the BOMs in the first place would probably be better.

In the meantime I've created a production-build.js file that hooks into the fetch and strips out the BOM:

const steal = require('steal');
const stealTools = require("steal-tools");

stealTools.build({
  debug: false,
  fetch: function(load){
    return steal.loader.fetch(load).then(function(source){
      if(/^\uFEFF/.test(source)){
        console.log(load.address);
      }

      return source.replace(/^\uFEFF/, '');
    });
  }
}, {
    bundleAssets: true,
    bundleSteal: true
});

I'm closing this issue but if you would like to add a stripBom build option I guess that wouldn't hurt ;)