简体   繁体   中英

React Dist Without Server, Node or Http-server

I have a simple React App that's using webpack to make a production dist, but when I open the index.html, it's nothing but a blank page. I tried meddling with webpack configs, searching the reason it may be, but I utterly failed.

I need to make a dist and be able to run the app with just the static files, no server, is that possible? Or do I really need a http server or node to serve files or modules even after compiling everything?

webpack.config.js

 'use strict'; /* eslint no-console: "off" */ const webpackConfigs = require('./conf/webpack'); const defaultConfig = 'dev'; module.exports = (configName) => { // If there was no configuration give, assume default const requestedConfig = configName || defaultConfig; // Return a new instance of the webpack config // or the default one if it cannot be found. let LoadedConfig = defaultConfig; if (webpackConfigs[requestedConfig] !== undefined) { LoadedConfig = webpackConfigs[requestedConfig]; } else { console.warn(` Provided environment "${configName}" was not found. Please use one of the following ones: ${Object.keys(webpackConfigs).join(' ')} `); LoadedConfig = webpackConfigs[defaultConfig]; } const loadedInstance = new LoadedConfig(); // Set the global environment process.env.NODE_ENV = loadedInstance.env; return loadedInstance.config; }; 

It is possible to host your app on S3 (and others) :

https://medium.com/@omgwtfmarc/deploying-create-react-app-to-s3-or-cloudfront-48dae4ce0af

For different deployment strategies you could have look at the CRA readme

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM