【发布时间】:2016-09-07 07:42:50
【问题描述】:
我有一个 grunt 设置来使用 webpack 和 grunt-webpack 捆绑我的反应文件。我没有使用webpack-dev-server,但我的咕噜声仍然输出错误为Cannot find module 'webpack-dev-server'
这是我的 grunt 文件:
var webpack = require("webpack");
var webpackConfig = require("./webpack.config.js");
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks("grunt-webpack");
grunt.initConfig({
eslint: {
options: {
configFile: 'eslint.json'
},
target: ['./react/components/**/*.js','./react/services/**/*.js', './node/source/**/*.js']
},
webpack: {
options: webpackConfig,
build:{}
},
watch: {
app: {
files: ['./react/main.js', './react/components/**/*.js','./react/services/**/*.js'],
tasks: ["webpack"],
options: {
spawn: false,
}
}
}
});
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('build', ['webpack']);
grunt.registerTask('default', ['watch']);
};
webpack.config.js文件
const path = require('path');
const buildDirectory = './node/static/js/';
module.exports = {
entry: './react/main.js',
resolve: {
extensions: ['', '.js', '.jsx'],
},
output: {
path: path.resolve(buildDirectory),
filename: 'bundle.js',
},
externals: {
'cheerio': 'window',
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
stats: {
assets: false,
colors: false,
modules: false,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015'],
},
}],
},
plugins: [],
};
错误输出
grunt build
Loading "webpack-dev-server.js" tasks...ERROR
>> Error: Cannot find module 'webpack-dev-server'
Loading "webpack-dev-server.js" tasks...ERROR
>> Error: Cannot find module 'webpack-dev-server'
Running "webpack:build" (webpack) task
Done.
如果我添加 webpack-dev-server 包,此错误将得到解决,但我不希望我的项目中有额外的依赖。
包:
"webpack": "^1.13.1",
"grunt-webpack": "^1.0.14",
"grunt": "^1.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^19.0.0",
【问题讨论】:
-
webpack-dev-servergrunt-webpack的开发和对等依赖项。 -
真的依赖吗?因为在文档中没有提到
-
好的,谢谢。不知道为什么没有安装,我再试试看输出。
标签: gruntjs webpack webpack-dev-server