【发布时间】:2017-12-29 09:37:15
【问题描述】:
以下 HTML 代码
<!DOCTYPE html>
<html lang="en">
<body>
Greeting below:
<div id="time">
{{greetings}}
</div>
<script src='bundle.js'></script>
</body>
</html>
连同entry.js 文件
// either the import or the require work
Vue = require('./vue.js')
//import Vue from './vue.js'
new Vue({
el: "#time",
data: {
greetings: "hello world"
}
})
还有webpack.config.js
module.exports = {
entry: './entry.js',
output: {
filename: 'bundle.js'
}
}
工作正常(vue.js 是从站点或 CDN 本地下载的)。
然后我尝试使用通过npm install vue --save-dev 安装的vue 模块,方法是将entry.js 更改为
import Vue from 'vue'
new Vue({
el: "#time",
data: {
greetings: "hello world"
}
})
这个版本不再工作了:整个<div>没有被渲染(只显示Greeting below)。
应该怎么做才能让 Vue.js 与 webpack 一起使用?
Vue 文档多次提到 webpack,但仅在组件或生产构建的上下文中。
【问题讨论】:
-
最近的浏览器版本现在支持原生导入。所以
webpack和其他node/npm行李可能不再需要简单的应用程序:developers.google.com/web/fundamentals/primers/modules
标签: javascript webpack vue.js webpack-2