How to bundle a React app to a subdirectory on a server?

前端 未结 10 2163
名媛妹妹
名媛妹妹 2020-12-04 14:41

I have a React app I\'ve been developing on my localhost. I want to copy it to a server into a subdirectory called vensa.

My webpack config file looks like this..

10条回答
  •  忘掉有多难
    2020-12-04 15:22

    Or you could use an environment variable to adjust all your links manually.

    const ENV = process.env.NODE_ENV || 'local'; //development
    const config = {
        publicPath: ENV !== 'production' ? '/' : '/dev/'
    };
    plugins: ([
            new webpack.DefinePlugin({
                'process.env.NODE_ENV': JSON.stringify(ENV),
                'process.env.config': JSON.stringify(config)
            })
    })
    

    Then one of your routes:

    
    

    Then your links:

    Account
    

    This worked great for me. Especially since I'm using preact, whose preact-router doesn't really support the basename at this time.

    
      
    
    

提交回复
热议问题