umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.39k stars 2.65k forks source link

umijs3 启动后如何自动打开浏览器 #4294

Closed eevin closed 4 years ago

eevin commented 4 years ago

没有配置.env webpack 配置config.devServer.open(true) 也不行

sorrycc commented 4 years ago

暂不支持。

luxueyan commented 4 years ago

这么好用的功能竟然 不支持的这么理所当然,感觉umi的有些思想太项目化,完全没有开源脚手架该有的考虑

youngjuning commented 4 years ago

竟然把这个功能删掉了,是什么样的考虑呀!

MingshuaiYu commented 4 years ago

oh my god!

pkaq commented 3 years ago

所以 支持了么?

xuanxuan321 commented 3 years ago

暂不支持。

能说下原因吗?这么好的功能下掉了着实可惜

RainManGO commented 3 years ago

devServer: { open: true, } 配置无效,有没有支持的计划?

cnInkHao commented 3 years ago

这个... 可惜了

yaohwu commented 2 years ago

I've tried several plugins,but no typescript version for me so I write a simple one using typescript.


// custom define webpack plugin
class openBrowser {
    constructor() {
        console.log("create open browser");
    }

    // noinspection JSUnusedGlobalSymbols
    apply(compiler: Compiler) {
        compiler.hooks.afterDone.tap("open browser", () => {
            console.log("open in browser");
            // can not load in same tab, bad
            open("http://localhost:3000/webapp");
        })
    }
}

But is there any way to make it open in the same browser tab instead of creating one new?

huangchen1031 commented 1 year ago

I use the PLUGIN open-browser-webpack-plugin

import openBrowser from 'open-browser-webpack-plugin';

export default defineConfig({
  // ... other config
  devServer: {
    port: process.env.PORT,
  },
  chainWebpack(config) {
    config
      .plugin('open-browser-webpack-plugin')
      .use(openBrowser, [{ url: `http://localhost:${process.env.PORT}` }]);
  },
});

you should add PORT in .env before