webpack打包vue2.0項目時必現問題

[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.html

(found in <Root>)vue

這個問題是怎麼形成的呢,找了好久找不處處理方法,上網查了也沒找到一個好的處理方案。後來去看官方文檔,找到了相似的答案。
圖片描述webpack

這是什麼意思呢?
運行時構建不包含模板編譯器,所以不支持 template 選項,只能用 render 選項,但即便使用運行時構建,在單文件組件中也依然能夠寫模板,由於單文件組件的模板會在構建時預編譯爲 render 函數。運行時構建比獨立構建要輕量30%,只有 17.14 Kb min+gzip大小。
上面一段是官方api中的解釋。就是說,若是咱們想使用template,咱們不能直接在客戶端使用npm install以後的vue。此時,再去看查vue模塊,添加幾行
resolve: {
alias: {
'vue': 'vue/dist/vue.js'
}
}
再運行,沒錯ok了。web

如下是個人完成的代碼
webpack.config.babel.jsnpm

/**
 * Created by lenovo on 2017/5/8.
 */import path from 'path';import HtmlWebpackPlugin from 'html-webpack-plugin';const config = {
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.join(__dirname, 'dist')
    },
    module: {
        loaders:[
            {
                test: /\.js$/,
                loader: 'babel'
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: './index.html',
            title: 'hello App'
        })
    ],
    resolve: {
        alias: {
            'vue': 'vue/dist/vue.js'
        }
    }}export default config;複製代碼

package.jsonjson

{
  "name": "demo",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "vue": "^2.3.2"
  },
  "devDependencies": {
    "babel-core": "^6.3.26",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.24.1",
    "html-webpack-plugin": "^2.28.0",
    "webpack": "^1.12.9",
    "vue-loader": "^12.0.3",
    "vue-template-compiler":"^2.3.2"
  }}複製代碼

不知道有沒有朋友遇到過這樣的問題,若是遇到了而你正好不知道怎麼解決,我想這篇文章會幫到你。api

相關文章
相關標籤/搜索