Сервер Webpack dev сгенерировал пакет js файл, НО ничего не отображает - PullRequest
0 голосов
/ 03 августа 2020

Недавно я отказался от реакции и попытался настроить webpack / babel для своего проекта. Пока я застрял в запуске сервера и не отображал ничего, кроме пустой страницы.

структура проекта:

dist

  • index_bundle. js

publi c

  • index. html

sr c

  • index. js

webpack.config. js

Вот мои файлы:

webpack.config. js

const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require('path');

module.exports = {
  
    entry: "./src/index.js",
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'index_bundle.js',
    },
    devServer: {
        compress: true,
        historyApiFallback: true,
        open: true,
        overlay: true,
        hot: true,
        contentBase: path.join(__dirname, "dist"),
    },
    module: {
        rules: [
        {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: {
            loader: "babel-loader"
            }
        },
        {
            test: /\.css$/i,
            use: ['style-loader', 'css-loader'],
        },
        {
            test: /\.svg$/,
            loader: 'svg-inline-loader'
        },
        {
            test: /\.(ttf|eot|svg|jpe?g|png|gif|woff(2)?)(\?[a-z0-9=&.]+)?$/,
            loader : 'file-loader'
        },
        ]
    },
    resolve: {
        extensions: [
        '.ts',
        '.js' // add this
        ]
    },
    plugins: [new HtmlWebPackPlugin({
        template: __dirname + '/public/index.html',
        filename: 'index.html',
        inject: 'body'
    })]
};

индекс. js

ReactDOM.render(
  <React.StrictMode>

      <Provider store={store}>
        <ReactReduxFirebaseProvider {...rrfProps}>
          <MuiThemeProvider theme={theme}>
                <App />
          </MuiThemeProvider>    
        </ReactReduxFirebaseProvider>
      </Provider>


  </React.StrictMode>,
  document.getElementById('root')
);

индекс. html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>Ad Manager</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>
...