webpack打包vue2.0項目時必現問題(轉載)

來源:互聯網
上載者:User

標籤:ted   module   3.2   上網   json   dem   .config   time   ade   

原文地址:http://www.imooc.com/article/17868

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

(found in <Root>)

這個問題是怎麼造成的呢,找了很久找不到處理方法,上網查了也沒找到一個好的處理方案。後來去看官方文檔,找到了類似的答案。


這是什麼意思呢?
運行時構建不包含模板編譯器,因此不支援 template 選項,只能用 render 選項,但即使使用運行時構建,在單檔案組件中也依然可以寫模板,因為單檔案組件的模板會在構建時先行編譯為 render 函數。運行時構建比獨立構建要輕量30%,只有 17.14 Kb min+gzip大小。
上面一段是官方api中的解釋。就是說,如果我們想使用template,我們不能直接在用戶端使用npm install之後的vue。此時,再去看查vue模組,添加幾行
resolve: {
alias: {
‘vue‘: ‘vue/dist/vue.js‘
}
}
再運行,沒錯ok了。

以下是我的完成的代碼
webpack.config.babel.js

/**
* 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.json

{
"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"
}
}
不知道有沒有朋友遇到過這樣的問題,如果遇到了而你正好不知道怎麼解決,我想這篇文章會幫到你。

相關標籤:Node.jsJavaScriptVue.js
本文原創發佈於慕課網 ,轉載請註明出處,謝謝合作!

webpack打包vue2.0項目時必現問題(轉載)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.