[英]Webpack issue when compiling JS files
I am working on a Laravel 5.3 project, I have been using webpack with no issues until I tried to add some configurations for ES6. 我正在研究Laravel 5.3项目,在尝试为ES6添加一些配置之前,我一直在使用webpack没问题。 These included addind babel packages to my npm module.
这些包括addind babel软件包到我的npm模块中。 It broke my code so I reverted back all the changes but now whenever I change a JS file and compile, this line is added to the final JS file and it causes the Vue instance to be undefined (The line appears whenever I run gulp whether I change a file or not).
它破坏了我的代码,所以我恢复了所有更改,但是现在每当我更改JS文件并进行编译时,此行就会添加到最终的JS文件中,这会导致Vue实例未定义(无论我是否运行gulp,该行都会出现更改文件)。 I am using this package
laravel-elixir-vue-2
and from what I have gathered(though I might be wrong) I do need any more configurations to run it successfully as I have been using it that way for a few months. 我使用的是
laravel-elixir-vue-2
软件包,从我收集的信息来看(尽管我可能是错的),我确实需要任何其他配置才能成功运行它,因为我已经使用了几个月。
/***/ function(module, exports) { 124 125 eval("var g;\\r\\n\\r\\n// This works in non-strict mode\\r\\ng = (function() { return this; })();\\r\\n\\r\\ntry {\\r\\n\\t// This works if eval is allowed (see CSP)\\r\\n\\tg = g || Function(\\"return this\\")() || (1,eval)(\\"this\\");\\r\\n} catch(e) {\\r\\n\\t// This works if the window reference is available\\r\\n\\tif(typeof window === \\"object\\")\\r\\n\\t\\tg = window;\\r\\n}\\r\\n\\r\\n// g can still be undefined, but nothing to do about it...\\r\\n// We return undefined, instead of nothing here, so it's\\r\\n// easier to handle this case. if(!global) { ...}\\r\\n\\r\\nmodule.exports = g;\\r\\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiOC5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8od2VicGFjaykvYnVpbGRpbi9nbG9iYWwuanM/");
/ *** /函数(模块,导出){124125 eval(“ var g; \\ r \\ n \\ r \\ n ///在非严格模式下起作用\\ r \\ ng =(function(){返回此; }}(); \\ r \\ n \\ r \\ ntry {\\ r \\ n \\ t //如果允许eval(请参阅CSP)\\ r \\ n \\ tg = g || Function(\\“ return this \\” )()||(1,eval)(\\“ this \\”); \\ r \\ n} catch(e){\\ r \\ n \\ t //如果窗口引用可用\\ r \\ n \\ tif (typeof window === \\“ object \\”)\\ r \\ n \\ t \\ tg = window; \\ r \\ n} \\ r \\ n \\ r \\ n // g仍可以不确定,但与此无关... \\ r \\ n //我们返回undefined,而不是这里未返回的任何内容,因此,\\ r \\ n //更容易处理这种情况。if(!global){...} \\ r \\ n \\ r \\ nmodule .exports = g; \\ r \\ n //#sourceMappingURL = data:application / json; charset = utf-8; base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiOC5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy8od2VicGFjaykvYnVn 126 126
126126
I have even cloned a previous version of my repo that was working but the issue persists. 我什至已经克隆了我的仓库的早期版本,但是该问题仍然存在。 At first I thought that some PHPStorm settings I had done caused it but then I changed the editor to use Atom but the issue did not go away.
起初我以为我完成了一些PHPStorm设置,但后来我将编辑器更改为使用Atom,但问题并没有消失。
UPDATE I followed this link to install babel so that I can use ES6 format inside my .vue files but it broke my webpack instead. 更新我按照此链接安装了babel,以便可以在.vue文件中使用ES6格式,但它破坏了我的webpack。 I have not used
use strict
anywhere in my code. 我没有在代码中的任何地方
use strict
。 I installed a clean git repo in another pc and it raised the issue too. 我在另一台PC上安装了一个干净的git repo,它也引起了问题。 Also it works where I have used vue outside
.vue
components 在我在
.vue
组件之外使用vue的地方也可以使用
This is my gulpfile.js 这是我的gulpfile.js
const elixir = require('laravel-elixir');
require('laravel-elixir-vue-2');
elixir(function(mix) {
mix.sass('app.scss')
.webpack('app.js');
});
Comment below if any further clarification is needed. 如果需要进一步澄清,请在下面发表评论。
我仍然不知道是什么引入了use strict
的use strict
但是最佳实践是将v-if
与任何无法定义的 变量一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.