简体   繁体   English

Vue.js:Laravel Mix无法合并文件

[英]Vue.js: Laravel Mix not combining files

I'm using Laravel 5.4 with Node.js 6, and Vue.js 2. 我正在将Laravel 5.4与Node.js 6和Vue.js 2一起使用。

In resources/assets/js/app.js I have: resources/assets/js/app.js我有:

require('./bootstrap');

window.Vue = require('vue');

Vue.use(require('vue-resource'));

In webpack.mix.js I have: webpack.mix.js我有:

mix.combine([
    'resources/assets/js/app.js',
    'resources/assets/js/enhanced.js',
    'resources/assets/js/search.js'
], 'public/js/app.js')
   .sass('resources/assets/sass/app.scss', 'public/css');

In resources/assets/js/enhanced.js I have: resources/assets/js/enhanced.js我有:

require('./app')

var Search = require('./components/Enhanced.vue');

const app = new Vue({
    el: '#app_page_enhanced',
    render: app_page_enhanced => app_page_enhanced(Page_Enhanced)
});

In resources/assets/js/search.js I have: resources/assets/js/search.js我有:

require('./app')

var Search = require('./components/Search.vue');

new Vue({
    el: '#app_search',
    render: app_search => app_search(Search)
})

I have npm run watch-poll running in a Terminal window. 我在终端窗口中运行了npm run watch-poll

However, I keep getting an error on line 8 of app.js : 但是,我在app.js第8行上不断收到错误消息:

require('./bootstrap'); require('./ bootstrap');

When I comment that line out, the process goes through without additional errors, but when I look at: public/js/app.js the separate .js files aren't included. 当我对该行进行注释时,该过程将继续进行,而不会出现其他错误,但是当我查看以下内容时: public/js/app.js不会包含单独的.js文件。

I've tried removing: require('./app') from the two .js files, and: 我试过从两个.js文件中删除: require('./app')和:

mix.combine([ ... ], 'public/js/')

... and: ...和:

mix.combine([ ... ], 'public/js/', 'public/js/app.js')

... but it made no difference. ...但是没什么区别。

It's worth mentioning that the code for Vue works when in the app.js file. 值得一提的是,Vue的代码在app.js文件中时有效。

I've cobbled this together based on the bits I've scavenged, as I've not been able to find an official guide. 由于无法找到正式指南,因此我根据所搜集的内容将其拼凑在一起。

Update 更新资料

In terms of the core problem, @tompec has helped fix it. 在核心问题方面,@ tompec帮助解决了该问题。

However, I thought this would cure the massive number of errors I get when running the search page and featured results page , where each page is executing the Vue code for both pages, causing the errors. 但是,我认为这可以解决运行搜索页面特色结果页面时出现的大量错误,其中每个页面都对两个页面执行Vue代码,从而导致错误。

Try to do something like that 尝试做这样的事情

mix.js([
    'resources/assets/js/app.js',
    'resources/assets/js/enhanced.js',
    'resources/assets/js/search.js'
], 'public/js/app.js')
   .sass('resources/assets/sass/app.scss', 'public/css');

and remove require('./app') from resources/assets/js/enhanced.js and from resources/assets/js/search.js . 并从resources/assets/js/enhanced.jsresources/assets/js/search.js删除require('./app')

And here's the doc: https://github.com/JeffreyWay/laravel-mix/tree/master/docs 这是文档: https : //github.com/JeffreyWay/laravel-mix/tree/master/docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM