Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic preferation of .web.js-files doesn't work #11

Closed
jhnns opened this issue Jul 10, 2012 · 6 comments
Closed

Automatic preferation of .web.js-files doesn't work #11

jhnns opened this issue Jul 10, 2012 · 6 comments

Comments

@jhnns
Copy link
Member

jhnns commented Jul 10, 2012

I'm not quite sure if I'm doing it wrong, but webpack uses the .js-file instead of the browser-compatible .web.js. This is my test setup:

// Creating bundle via API

var webpack = require("webpack");

webpack(__dirname + "/testEntry.js", {
    output: __dirname + "/testBundle.js"
}, function onWebpackFinished(err, stats) {
    if (err) throw err;
    console.log(stats.fileModules["testBundle.js"]);
});
// testEntry.js
var bla = require("./bla.js");
// bla.js
module.exports = "bla";
// bla.web.js
module.exports = "bla.web";
[ { id: 0,
    size: 81,
    filename: '[...]/testEntry.js',
    dirname: undefined,
    fromCache: undefined,
    toCache: undefined,
    reasons: [ [Object] ] },
  { id: 1,
    size: 69,
    filename: '[...]/bla.js',
    dirname: undefined,
    fromCache: undefined,
    toCache: undefined,
    reasons: [ [Object] ] } ]

bla.js and bla.web.js are in the same folder. The error occurs on linux and windows. My current webpack version is 0.4.12. Any idea? :)

@jhnns
Copy link
Member Author

jhnns commented Jul 10, 2012

Same thing when using the command line.

@sokra
Copy link
Member

sokra commented Jul 10, 2012

require('./bla')

.web.js is the preferred extension for extension expansion. Specifying the complete filename do not try the .web.js extension.

@sokra
Copy link
Member

sokra commented Jul 10, 2012

@sokra
Copy link
Member

sokra commented Jul 10, 2012

If you want to enforce .web.js even for all .js files, you can archive this by a resolve postprocessor:

resolve: {
 postprocess: {
  normal: [
    function(filename, cb) {
      var file = filename.split("!").pop();
      if(!/\.js$/.test(file)) return callback(null, filename);
      file = file.replace(/\.js$/, ".web.js");
      fs.exists(file, function(exists) {
        if(!exists) return callback(null, filename);
        return callback(null, filename.replace(/\.js$/, ".web.js"));
      });
    }
  ]
 }
}

@jhnns
Copy link
Member Author

jhnns commented Jul 10, 2012

Thanks, require('./bla') did the trick. I should read the readme more attentively ;).

What exactly is a postprocessor in webpack? Is this ability documented?

@jhnns
Copy link
Member Author

jhnns commented Jul 10, 2012

Sorry, now I've read the next issue #7.

@sokra sokra closed this as completed Jul 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants