2017-05-08 137 views
1

我是vue.js和webpack的新手,我无法编译我的vue文件。webpack,vue.js,无法编译vue文件

我使用Spring的引导和卵石作为模板技术,我想生成一个.js文件和包括它在我的index.pebble

这里是我的webpack.config.js

module.exports = { 
    // This is the "main" file which should include all other modules 
    entry: './src/main/resources/static/app/main.js', 
    // Where should the compiled file go? 
    output: { 
     // To the `dist` folder 
     path: './src/main/resources/static/lib', 
     // With the filename `build.js` so it's dist/build.js 
     filename: 'build.js' 
    }, 
    module: { 
     // Special compilation rules 
     loaders: [ 
      { 
       // Ask webpack to check: If this file ends with .js, then apply some transforms 
       test: /\.js$/, 
       // Transform it with babel 
       loader: 'babel', 
       // don't transform node_modules folder (which don't need to be compiled) 
       exclude: /node_modules/ 
      }, 
      { 
       test: /\.vue$/, 
       loader: 'vue' 
      } 
     ] 
    }, 
    vue: { 
     loaders: { 
      js: "babel-loader?presets[]=es2015,presets[]=stage-2" 
     } 
    }, 

} 

我的文件babelrc:

{ 
    "presets": ["es2015", "stage-0"], 
    "plugins": ["transform-runtime"] 
} 

我的文件的package.json

{ 
    "name": "xxxx", 
    "version": "1.0.0", 
    "description": "TODO", 
    "scripts": { 
    "watch-build": "echo \"not available\" && exit 1", 
    "build": "npm install", 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "LMFR", 
    "readmeFilename": "README.md", 
    "devDependencies": { 
    "babel-core": "^6.1.2", 
    "babel-loader": "^6.1.0", 
    "babel-preset-latest": "^6.16.0", 
    "babel-preset-stage-2": "^6.18.0", 
    "babel-runtime": "^5.8.0", 
    "webpack": "^1.12.2", 
    "css-loader": "^0.23.0", 
    "style-loader": "^0.13.0", 
    "vue-loader": "^7.3.0", 
    "vue-html-loader": "^1.0.0" 
    }, 
    "dependencies": { 
    "vue": "^2.3.2" 
    } 
} 

这是我main.js

进口Vue公司从 'VUE' //导入应用程序从 './app.vue'

new Vue({ 
    el: '#app', 
    template: '<p>haaaa</p>' 
}) 

而且我现在面临的错误:

build.js:494 [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build. 
+0

你可以发布你的主要vuejs文件?你在哪里实例化新的Vue对象? –

+0

也许这可以帮助你[试图与Vue 2一起使用](https://github.com/vuejs-templates/webpack/issues/215) – Gerardo

+0

@BelminBedak,我加了它 – Seb

回答

0

如果您在运行时只有建立您不能使用模板属性,而必须使用渲染功能或包括模板编译器。

尝试改变main.js到

import Vue from 'vue' //import App from './app.vue' 

new Vue({ 
    el: '#app', 
    render: function(createElement) { 
     return createElement(
      'p', 
      'haaaa' 
     ) 
    } 
}) 

JsFiddle工作拨弄

当的WebPack工作.vue文件将能从<template></template>标签编译但主要Vue的根必须使用渲染功能这通常看起来像

import Vue from 'vue' 
import App from './app.vue' 

new Vue({ 
    el: '#app', 
    render: function(createElement) { 
     return createElement(
      App 
     ) 
    } 
})