首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证和Webpack Encore编译错误

验证和Webpack Encore编译错误
EN

Stack Overflow用户
提问于 2019-07-02 19:03:29
回答 1查看 1K关注 0票数 1

我创建了(目前独立的) API和一个VueJs (使用Vuetify)应用程序,并希望使用Symfony的webpack encore捆绑包将两者结合起来。

但是,当我想要构建前端应用程序时,在执行yarn run encore dev时会出现以下错误

代码语言:javascript
复制
(node:12500) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at items.forEach.item (/Users/pguetschow/Projects/hosting-tool/node_modules/vuetify-loader/lib/loader.js:21:60)
    at Set.forEach (<anonymous>)
    at Object.getMatches (/Users/pguetschow/Projects/hosting-tool/node_modules/vuetify-loader/lib/loader.js:16:9)
    at Object.module.exports (/Users/pguetschow/Projects/hosting-tool/node_modules/vuetify-loader/lib/loader.js:106:64)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:12500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12500) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的webpack.config.js

代码语言:javascript
复制
const Encore = require('@symfony/webpack-encore');
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin');

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    .cleanupOutputBeforeBuild()
    .addEntry('js/main', './assets/js/main.js')
    .enableVueLoader()
    .enableBuildNotifications(true)
    .addPlugin(new VuetifyLoaderPlugin())
;
module.exports = Encore.getWebpackConfig();

有什么想法吗?独立的应用程序运行良好,我只需将其移动到assets/js文件夹即可。为此,我需要vuetify loader^1.2.2。

这是我的main.js

代码语言:javascript
复制
import Vue from 'vue'
import App from './App.vue'
import Vuetify from 'vuetify/lib'
import MultiFiltersPlugin from './plugins/MultiFilters'

import 'vuetify/src/stylus/app.styl'
import 'material-design-icons-iconfont/dist/material-design-icons.css'
import 'vuetify/dist/vuetify.min.css'

Vue.use(MultiFiltersPlugin);
Vue.use(Vuetify, {
    iconfont: 'md',
});

new Vue({render: h => h(App),}).$mount('#app');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-27 10:28:27

这是一个来自this working example的示例webpack.config.js文件,它展示了如何让Symfony和v.2x一起合作:

代码语言:javascript
复制
var Encore = require('@symfony/webpack-encore');

// import vuetify-loader as a plugin here
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')

if (!Encore.isRuntimeEnvironmentConfigured()) {
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}

Encore
    .setOutputPath('public/build/')
    .setPublicPath('/build')
    .enableVueLoader() // <-- IMPORTANT: this loads Vue
    // NOTE: I put my Vue app in assets/vue which I think is non-standard
    //       but it allows me to structure my Vue app as I would in a non-Symfony app
    .addEntry('app', './assets/vue/main.js')
    .splitEntryChunks()
    .enableSingleRuntimeChunk()
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning(Encore.isProduction())
    .configureBabel(() => {}, {
        useBuiltIns: 'usage',
        corejs: 3
    })
    // add VuetifyLoaderPlugin: THIS loads all of the Vuetify components
    .addPlugin(new VuetifyLoaderPlugin())
    // enables Sass/SCSS support
    .enableSassLoader(options => {
        options.implementation = require('sass')
        options.fiber = require('fibers')
    })
;

module.exports = Encore.getWebpackConfig();

注意,我不是一个真正的symfony开发人员,但这对我很有效。哈!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56851039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档