3
votes

I'm new to vue.js and webpack and I'm having trouble compiling my vue files.

I'm using Spring boot and pebble as templating technology and I want to generate a single .js file and include it in my index.pebble

Here is my 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"
        }
    },

}

my file babelrc :

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

my file 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"
  }
}

Here is my main.js

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

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

And the error I'm facing :

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.
2
And could you post your main vuejs file ? where you instantiate new Vue object ?Belmin Bedak
Maybe this could help you Trying to use this with Vue 2Gerardo
@BelminBedak, I added itSeb
Well as error says you can't use template in runtime-build :)Belmin Bedak
@BelminBedak can you tellme more ? As I said, I'm quite new to these technologiesSeb

2 Answers

6
votes

Look at the webpack-simple vue-cli template as a guide, I believe you are missing a dependency:

https://github.com/vuejs-templates/webpack-simple/blob/master/template/package.json#L26

 "vue-template-compiler": "^2.2.1",
0
votes

If you have the runtime only build you can not use the template property and must instead use a render function or include a template compiler.

try changing the main.js to

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

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

JsFiddle Working fiddle

When working with Webpack .vue files will be able to be compiled from <template></template> tags but the main Vue root must use a render function which generally looks like

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

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