modernizr-loader icon indicating copy to clipboard operation
modernizr-loader copied to clipboard

Compatibility with modernizr-server

Open rlindskog opened this issue 8 years ago • 0 comments

Hi,

I just made some middleware to handle fetching modernizr information to the server. It's called modernizr-server. Do you think its possible to change the wrapOutput function while targetting node to something like this? Not to experience with building webpack loaders.

function wrapOutput(output) {
    // Exposing Modernizr as a module.
    return ";(function(global){\n" +
         "var hadGlobal = 'Modernizr' in global;\n" +
         "var oldGlobal = global.Modernizr;\n" +
         "global.Modernizr = `" + output + "`\n" +
         "module.exports = global.Modernizr;\n" +
         "if (hadGlobal) { global.Modernizr = oldGlobal; }\n" +
         "else { delete global.Modernizr; }\n" +
    "})(global);";
}

This would just make expose the modernizr build as a string that modernizr-server would send to the client to be executed.

It would work with modernizr-server like this.

app.use(modernizrServer({
  build: Modernizr
}))

app.get('/', function(req, res) {
  let Moderizr = req.cookies.modernizr
}

see modernizr-server for more information.

rlindskog avatar Jan 17 '17 20:01 rlindskog