Symfony + Vue:从不加载Vue组件?

时间:2019-01-30 18:30:08

标签: symfony vue.js webpack symfony4 webpack-encore

我将Vue弹出到Symfony 4项目中,并且遵守了所有可以找到的规则。由于某些原因,我无法显示任何Vue组件-我什至无法从我的app.js文件夹执行console.log。

这是app.js:

var Vue = require('vue');
import App from './components/App'
console.log('testing')
new Vue({
    el: '#app',
    template: '<App/>',
    components: { App },
});

下面的webpack.config:

var Encore = require('@symfony/webpack-encore');

再来一次     //将存储已编译资产的目录     .setOutputPath( '公共/编译/')     // Web服务器用来访问输出路径的公共路径     .setPublicPath( '/构建')     //仅CDN或子目录部署需要     //。setManifestKeyPrefix('build /')

/*
 * ENTRY CONFIG
 *
 * Add 1 entry for each "page" of your app
 * (including one that's included on every page - e.g. "app")
 *
 * Each entry will result in one JavaScript file (e.g. app.js)
 * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
 */
.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()

/*
 * FEATURE CONFIG
 *
 * Enable & configure other features below. For a full
 * list of features, see:
 * https://symfony.com/doc/current/frontend.html#adding-more-features
 */
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

// enables Sass/SCSS support
// .enableSassLoader()
.enableSassLoader(function(options) {}, {
    resolveUrlLoader: false
})

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you're having problems with a jQuery plugin
.autoProvidejQuery()
.enableVueLoader()
;

module.exports = Encore.getWebpackConfig();

这是我的模板:

            {% block content %}
             <div id="app"></div>
            {% endblock %}

就像我说的那样,即使当直接从app.js获取console.log时,它在控制台中也不做任何事情。我敢肯定,构建是获得app.js文件,如我的消息来源我看到的应用。####。加载JS(哈希版本),它包含了我写的代码。

1 个答案:

答案 0 :(得分:3)

确保模板中包含{{ encore_entry_script_tags('app') }}