{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel-loader/issues/166","repository_url":"https://api.github.com/repos/babel/babel-loader","labels_url":"https://api.github.com/repos/babel/babel-loader/issues/166/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel-loader/issues/166/comments","events_url":"https://api.github.com/repos/babel/babel-loader/issues/166/events","html_url":"https://github.com/babel/babel-loader/issues/166","id":118891408,"number":166,"title":"`resolveLoader.root` not being taken into account?","user":{"login":"julen","id":16768,"avatar_url":"https://avatars.githubusercontent.com/u/16768?v=3","gravatar_id":"","url":"https://api.github.com/users/julen","html_url":"https://github.com/julen","followers_url":"https://api.github.com/users/julen/followers","following_url":"https://api.github.com/users/julen/following{/other_user}","gists_url":"https://api.github.com/users/julen/gists{/gist_id}","starred_url":"https://api.github.com/users/julen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julen/subscriptions","organizations_url":"https://api.github.com/users/julen/orgs","repos_url":"https://api.github.com/users/julen/repos","events_url":"https://api.github.com/users/julen/events{/privacy}","received_events_url":"https://api.github.com/users/julen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2015-11-25T17:57:45Z","updated_at":"2016-07-19T18:15:47Z","closed_at":null,"body":"*(I'm not sure if this issue/question belongs here so apologies if that's not the case)*\r\n\r\nI'm using Babel 6 and I'm trying to use babel-loader for code which lives in a 3rd party directory, i.e. it's not a parent folder of *webpack.config.js*. This is accessible to webpack via [`resolve.root`](http://webpack.github.io/docs/configuration.html#resolve-root). \r\nBesides that, I'm setting `resolveLoader: { root: path.join(__dirname, 'node_modules') }` as [described in the webpack documentation](http://webpack.github.io/docs/configuration.html#module-loaders).\r\n\r\nThis *seems* to work as the Babel code is run. However, it complains about the `es2015` preset being missing:\r\n```\r\nModule build failed: Error: Couldn't find preset \"es2015\" relative to directory \"myDirectory\"\r\n    at OptionManager.mergePresets (~/node_modules/babel-core/lib/transformation/file/options/option-manager.js:327:17)\r\n    at OptionManager.mergeOptions (~/node_modules/babel-core/lib/transformation/file/options/option-manager.js:287:12)\r\n    at OptionManager.init (~/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)\r\n    at File.initOptions (~/node_modules/babel-core/lib/transformation/file/index.js:190:75)\r\n    at new File (~/node_modules/babel-core/lib/transformation/file/index.js:121:22)\r\n    at Pipeline.transform (~/node_modules/babel-core/lib/transformation/pipeline.js:42:16)\r\n    at transpile (~/node_modules/babel-loader/index.js:14:22)\r\n    at ~/node_modules/babel-loader/lib/fs-cache.js:140:16\r\n    at ReadFileContext.callback (~/node_modules/babel-loader/lib/fs-cache.js:27:23)\r\n    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:324:13)\r\n @ multi editor\r\n```\r\n(here `myDirectory` is the 3rd party directory).\r\n\r\nOf course if I `npm install babel-loader babel-core babel-preset-es2015` in the 3rd party directory it works, however, if I understand it correctly, that defeats the purpose of webpack's `resolveLoader.root`.\r\n\r\nAm I missing something? Is there something wrong in my understanding? And more importantly, does anyone have any suggestions on how to proceed? Thanks in advance!"},"comment":{"url":"https://api.github.com/repos/babel/babel-loader/issues/comments/233719613","html_url":"https://github.com/babel/babel-loader/issues/166#issuecomment-233719613","issue_url":"https://api.github.com/repos/babel/babel-loader/issues/166","id":233719613,"user":{"login":"vladimiry","id":1560781,"avatar_url":"https://avatars.githubusercontent.com/u/1560781?v=3","gravatar_id":"","url":"https://api.github.com/users/vladimiry","html_url":"https://github.com/vladimiry","followers_url":"https://api.github.com/users/vladimiry/followers","following_url":"https://api.github.com/users/vladimiry/following{/other_user}","gists_url":"https://api.github.com/users/vladimiry/gists{/gist_id}","starred_url":"https://api.github.com/users/vladimiry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladimiry/subscriptions","organizations_url":"https://api.github.com/users/vladimiry/orgs","repos_url":"https://api.github.com/users/vladimiry/repos","events_url":"https://api.github.com/users/vladimiry/events{/privacy}","received_events_url":"https://api.github.com/users/vladimiry/received_events","type":"User","site_admin":false},"created_at":"2016-07-19T18:15:47Z","updated_at":"2016-07-19T18:15:47Z","body":"Btw you can also pass plugins/presets arrays filled with references, not the strings. You require needed stuff first:\r\n```javascript\r\n    const babelPresets = [\r\n        require('babel-preset-es2015')\r\n    ];\r\n    const babelPlugins = [\r\n        require('babel-plugin-transform-class-properties')\r\n    ];\r\n```\r\nAnd then you connect that to the webpack's config with `babel` property name:\r\n```\r\n        babel: {\r\n            presets: babelPresets,\r\n            plugins: babelPlugins,\r\n            cacheDirectory: true\r\n        }\r\n```\r\nIn this case obviously babel doesn't resolve plugins/presets locations by string names, but uses passed by the reference instances. But it's not a very flexible way since it's a global config, not the per loader config. Passing instantiated plugins/presets references to the loader's `query` property doesn't work since webpack converts references to strings.\r\n\r\nI did a brief issue debugging and so far for me it looks like that it's not in babel-loader power to make `resolveLoader.root` webpack's property work for babel since babel resolves plugins/presets modules locations based on the processed file and babel has no explicit option like `modules root directory`."}}
{"actor":{"display_login":"vladimiry"}}