I'm trying to convert an existing website to use webpack, but all the existing require paths are absolute:
var Component = require('/path/to/my/component');
I've been reading through the webpack documentation and also found this answer about resolving paths, but wasn't quite able to solve my problem. When setting resolve.root
per the instructions in the answer above, I was able to get the following to work:
var Component = require('./path/to/my/component');
var Component = require('path/to/my/component');
However, I still can't figure out how to get the absolute path working and I would really prefer not to have to go through and update all my paths. Here's the site structure:
/app
/assets
/javascripts
/build
package.js
index.js
/node_modules
webpack.config.js:
var JS_ROOT = __dirname + '/app/assets/javascripts');
module.exports = {
entry: JS_ROOT + '/index',
output: {
path: JS_ROOT + '/build',
filename: 'package.js'
},
...
resolve: {
root: JS_ROOT
}
};
The error I keep getting is:
Module not found: Error: Cannot resolve 'file' or 'directory' /path/to/component in /Users/<username>/<ProjectRoot>/app/assets/javascripts
What am I doing wrong?