【发布时间】:2018-01-23 09:18:25
【问题描述】:
所以我正在使用 Grunt + Grunt-Browserify + Vue + Vueify 设置一个项目,但在访问“vue”模块时遇到问题。
这是我的文件夹结构:
app/
build/
app.js
app.vue
grunt/
node_modules/
Gruntfile.js
packaje.json
这是我的 Gruntfile 的内容:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
vendor: {
src: ['../app/app.js'],
dest: '../app/build/app.js',
options: {
watch: true,
keepAlive: true,
browserifyOptions: {
debug: true
},
transform: ['vueify']
}
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['browserify']);
};
这是我的 app.js 的内容:
var Vue = require('vue');
var App = require('./app.vue');
new Vue({
el: '#app',
render: function (createElement) {
return createElement(App);
}
});
当我运行grunt 时,我得到找不到模块'vue'
如果我像这样设置变量Vue:
var Vue = require(__dirname + '/' + 'vue');
我收到此错误Cannot find module 'vue-hot-reload-api'
如果我将 app 文件夹放在 grunt 文件夹中与 node_modules 相同的级别,并且变量 Vue 设置如下: var Vue = require('vue'); 一切正常。
我怎样才能让它工作,以便无论我的应用程序位于何处,我总能找到一个模块。
谢谢你,祝你有美好的一天:)
【问题讨论】: