javascript - Dynamic file path in require with webpack? -
this works fine when manually request file using require
, moment use exact same request, change string it's split variables fails.
this works great:
module.exports = (function() { var $svg = require('svg-inline!../../assets/svgs/global/connected.svg'); console.log($svg); }());
however if this:
module.exports = (function() { var $path = '../../assets/svgs/global/'; var $svg = require('svg-inline!'+$path+'connected.svg'); console.log($svg); }());
it fails , says inside console:
uncaught error: cannot find module "."
i guess question why can't concatenate strings have here?
i think have webpack context. when try require contains expression, webpack create context. expression treated regular expression , doesn't work may expect.
Comments
Post a Comment