Webpack 网页包,vue.js,can';无法编译vue文件
我是vue.js和webpack的新手,在编译vue文件时遇到问题 我使用SpringBoot和pebble作为模板技术,我想生成一个.js文件并将其包含在index.pebble中 这是我的webpack.config.jsWebpack 网页包,vue.js,can';无法编译vue文件,webpack,vue.js,babeljs,vuejs2,Webpack,Vue.js,Babeljs,Vuejs2,我是vue.js和webpack的新手,在编译vue文件时遇到问题 我使用SpringBoot和pebble作为模板技术,我想生成一个.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/m
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"
}
},
}
我的文件:
{
"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"
}
}
这是我的main.js
从“Vue”导入Vue
//从“./App.vue”导入应用程序
new Vue({
el: '#app',
template: '<p>haaaa</p>'
})
请参考vue cli模板,我认为您缺少一个依赖项:
如果只有运行时生成,则不能使用template属性,而必须使用呈现函数或包含模板编译器 尝试将main.js更改为
import Vue from 'vue' //import App from './app.vue'
new Vue({
el: '#app',
render: function(createElement) {
return createElement(
'p',
'haaaa'
)
}
})
工作小提琴
使用网页包.vue
时,可以从
标记编译文件,但主vue根目录必须使用呈现函数,该函数通常类似于
import Vue from 'vue'
import App from './app.vue'
new Vue({
el: '#app',
render: function(createElement) {
return createElement(
App
)
}
})
你能发布你的vuejs主文件吗?在哪里实例化新的Vue对象?也许这可以帮助您@BelminBedak,我添加了它,错误是说您不能在运行时构建中使用模板:)@BelminBedak您能告诉我更多吗?正如我所说,我对这些技术非常陌生
import Vue from 'vue' //import App from './app.vue'
new Vue({
el: '#app',
render: function(createElement) {
return createElement(
'p',
'haaaa'
)
}
})
import Vue from 'vue'
import App from './app.vue'
new Vue({
el: '#app',
render: function(createElement) {
return createElement(
App
)
}
})