我正在尝试使用webpack-dev-server
为我的个人项目组织一个webpack 2模板,并使用npm命令运行它,但我收到此错误:
Configuration file found but no entry configured.
这很奇怪,因为条目是定义的,我测试了已解决的路由,没关系,所以这里是我的webpack配置,运行它的命令和配置加载器的文件:
const path = require('path');
const fs = require('fs');
const configs = require('./dev-wpk-conf');
const HtmlPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const webpack = require('webpack');
const dirPath = fs.realpathSync(process.cwd());
const config = {
entry: {
bundle: path.resolve(dirPath, '../src/index.js'),
vendor: configs.vendor
},
output: {
path: path.resolve(dirPath, '../dist'),
filename: '[name].[hash].js'
},
devServer: {
port: 3030
},
module: {
rules: [
configs.jsonLoader,
configs.babelLoader,
configs.imgLoader,
configs.sassLoader
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({ names: ['vendor', 'manifest'] }),
new HtmlPlugin({ template: './src/index.html' }),
new Dotenv()
]
}
const vendor = [
'react',
'react-dom',
'react-redux',
'react-router',
'redux',
'redux-form',
'redux-thunk',
'redux-devtools-extension'
];
const jsonLoader = {
test: /\.json$/,
loader: 'json-loader'
};
const babelLoader = {
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['babel-preset-env', 'react']
}
};
const imgLoader = {
test: /\.(jpe?g|png|gif|svg)$/,
use: [
{ loader: 'url-loader', options: { limit: 40000 } },
'image-webpack-loader'
]
};
const sassLoader = {
test: /\.(scss|sass)$/,
use: [
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
],
fallback: 'style-loader'
};
module.exports = {
vendor,
jsonLoader,
babelLoader,
imgLoader,
sassLoader
};
"clean": "rimraf dist",
"serve": "yarn clean && webpack-dev-server --config ./config/webpack.config.dev.js"
config/
dev-wpk-conf.js
prod-wpk-conf.js
webpack.config.dev.js
webpack.config.prod.js
node_modules/
...
src/
index.js
// the app code
package.json
.env
//rc files
那么,为什么我得到这个错误呢?我不是专家,但是条目已经定义,解决的路径(再次)是正确的。
任何提示?
答案 0 :(得分:8)
您必须在webpack.config.dev.js中导出您的webpack配置。
添加此行添加配置文件的结尾。
module.exports = config;
答案 1 :(得分:0)
您可以将webpack用作可执行程序或节点模块。在您的情况下,您将其用作程序,因此您必须按照已经提到的
导出配置对象module.exports = config;