如何使用 - open 标志启动 webpack-dev-server 来打开我的publicPath?
目前它打开了一个浏览器标签 http://localhost:3000 ,但我希望它直接打开 http://localhost:3000/app ,这是我定义的公共路径
在启动 webpack-dev-server 后手动键入 http://localhost:3000/app 时,它会按预期工作。
这是我的 webpack.config.js ,到目前为止效果很好:
+------+-------+------+
|userId|movieId|rating|
+------+-------+------+
|3 |1 |1.0 |
|2 |2 |1.0 |
|1 |2 |1.0 |
|1 |1 |1.0 |
|2 |1 |1.0 |
|3 |2 |1.0 |
+------+-------+------+
答案 0 :(得分:13)
在您的情况下,值为/app
。
您还可以重写一些配置,这样就不必传递cli命令。
output: {
publicPath: '/app',// deploy on server with /app/ folder name
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'public')
},
devServer: {
contentBase: './dist',
host: 'localhost',
port: '3000',
inline: true,
compress: true,
proxy: {
'/api/**': {
target: 'http://10.189.1.159:8080',
secure: false,
changeOrigin: true,
cookieDomainRewrite: true
}
}
open: true, // Here
openPage: '/app' // And here
},
答案 1 :(得分:0)
before
option:module.exports = {
//...
devServer: {
before: function(app, server) {
app.get('/', function(req, res) {
res.redirect('/app'); // here you can try any of the Express JS res options mentioned in the answer below:
});
}
}
};
Documentation for Express.js response
祝你好运...