我正在尝试通过 WebPack 运行我的 React 应用程序,但该工具似乎忽略了我的端口设置。相反,它使用默认8080端口或随机端口(每次运行项目时都会有所不同)。webpack.development.config.js这是我的文件的摘录:
const path = require('path')
const appJsPath = path.join(__dirname, './src')
const bundelJsPath = path.join(__dirname, './build')
module.exports = {
devtool: 'inline-cheap-module-source-map',
context: appJsPath,
mode: 'development',
entry: {
myApp: [
'babel-polyfill',
'./main.js'
]
},
devServer: {
contentBase: path.join(bundelJsPath, '[name].bundle.js'),
port: 4040
},
// output: {
// path: bundelJsPath,
// filename: '[name].bundle.js',
// publicPath: 'http://localhost:4000/'
// },
我检查了端口4000和4040,它们没有被任何进程使用(我在 Windows 10 系统上)。我已经尝试了这两种设置,devServer和output,但它们都不起作用。重新启动系统也没有帮助。我究竟做错了什么?
我通过运行启动应用程序yarn dev:
"scripts": {
"dev": "yarn run clean && webpack-serve --config ./webpack.development.config.js && yarn run css",
"clean": "rimraf ./build",
"css": "uglifycss ./css/style.css > ./css/style.min.css"
}