{"action":"opened","issue":{"url":"https://api.github.com/repos/vuejs/vue-loader/issues/531","repository_url":"https://api.github.com/repos/vuejs/vue-loader","labels_url":"https://api.github.com/repos/vuejs/vue-loader/issues/531/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vue-loader/issues/531/comments","events_url":"https://api.github.com/repos/vuejs/vue-loader/issues/531/events","html_url":"https://github.com/vuejs/vue-loader/issues/531","id":194771331,"number":531,"title":"vue文件使用多个loader时不能正常工作","user":{"login":"zhangfisher","id":2050579,"avatar_url":"https://avatars.githubusercontent.com/u/2050579?v=3","gravatar_id":"","url":"https://api.github.com/users/zhangfisher","html_url":"https://github.com/zhangfisher","followers_url":"https://api.github.com/users/zhangfisher/followers","following_url":"https://api.github.com/users/zhangfisher/following{/other_user}","gists_url":"https://api.github.com/users/zhangfisher/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangfisher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangfisher/subscriptions","organizations_url":"https://api.github.com/users/zhangfisher/orgs","repos_url":"https://api.github.com/users/zhangfisher/repos","events_url":"https://api.github.com/users/zhangfisher/events{/privacy}","received_events_url":"https://api.github.com/users/zhangfisher/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-10T14:35:18Z","updated_at":"2016-12-10T14:35:18Z","closed_at":null,"body":"以下是我写的一个简单的loader，用来将vue文件里面的L(\"aaaas\")替代成L(\"aaaas\",\"talk\")样式\r\n在webpack里面是这样配置的:\r\n`\r\n        {\r\n                    test: /\\.vue$/,\r\n                    loader: 'vue-loader!lang-loader'\r\n        }\r\n`\r\n这个加载器的作用是用来进行处理多语言时使用的。\r\n但我发现lang-loader可以正常运行，在console.log跟踪也可以正常进行字符串的替换的\r\n但是结果输出时并没有，好象vue-loader只对原始文件进行处理，而不是在上一个输入的基础上\r\n处理。\r\n\r\n加载器的代码如下：\r\n`\r\n//本加载器用来专门处理多语言文件中的Region问题\r\n// 将文件里的翻译函数注入Region变量\r\n// 如 L(\"要翻译的内容\")\r\n// 如果上述语言定义在一个叫iptalk的翻译域中，\r\n// 则将其转换成L(\"要翻译的内容\",\"iptalk\")\r\n// \r\n\r\nvar langConfig = require(\"../src/language/language.config.json\")\r\nvar loaderUtils = require('loader-utils');\r\nvar path =  require(\"path\")\r\n\r\n//  L(\"dfsdfds\")\r\nvar langRegExp = new RegExp(/\\bL\\(\\\"(.*?)\\\"\\)/g)\r\n\r\n\r\n//根据文件名称返回其所在的Region\r\nfunction getfileRegion(srcFile){\r\n\tvar resultRegion=\"main\"\r\n\tfor(region in langConfig.regions || {}){\r\n\t\tvar regPath=path.resolve(__dirname,\"../src\",langConfig.regions[region])\r\n\t\tvar ref=path.relative(regPath,srcFile)\r\n\t\tif(!(ref==srcFile || ref.slice(0,2)==\"..\")){\r\n\t\t\tresultRegion=region\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn resultRegion\r\n}\r\n\r\nmodule.exports = function(source) {\r\n  var query = loaderUtils.parseQuery(this.query);\r\n  var region=getfileRegion(this.resourcePath)\r\n  if(region!=\"main\"){\r\n  \tsource=source.replace(langRegExp,'L(\"$1\",\"' + region + '\")')\r\n  }\r\n  return source\r\n};\r\n`"}}
{"actor":{"display_login":"zhangfisher"}}