当我运行webpack-dev-server时,屏幕上仅显示~/
。我正在尝试将Webpack与节点应用程序一起使用而没有反应。
我已经很长时间没有使用过webpack了,并且从未将它与node一起使用过,所以我可能完全做错了什么,所以如果您在我的webpack配置中看到它,请指出并告诉我为什么是错误的,应如何使用。
我感觉自己做的块错误,没有文件在服务器上,但我不是很积极吗?
命令:webpack-dev-server --config webpack.dev.js
这是我的应用程序:
import { ApolloServer } from 'apollo-server'
import { schema } from './modules'
const server = new ApolloServer({
schema
})
server.listen().then(({ url }) => {
console.log(` Server ready at ${url}`)
})
这是我的webpack.common.js
:
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const CleanWebpackPlugin = require('clean-webpack-plugin')
module.exports = {
target: `node`,
externals: [nodeExternals()],
watch: true,
watchOptions: {
ignored: /node_modules/
},
entry: {
main: path.resolve(__dirname, 'server/app.js')
},
output: {
filename: `[name].[hash].js`,
path: path.resolve(__dirname, `dist`)
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader'
},
{
test: /\.(graphql|gql)$/,
use: 'graphql-tag/loader'
}
]
},
optimization: {
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
node_vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
priority: 1
}
}
}
},
plugins: [new CleanWebpackPlugin()]
}
webpack.dev.js
:
const merge = require('webpack-merge')
const common = require('./webpack.common.js')
const path = require('path')
module.exports = merge(common, {
mode: 'development',
devServer: {
host: 'localhost',
port: 3000,
open: true,
hot: true,
contentBase: path.join(__dirname, 'dist')
}
})