Do not respond to rendering on Webpack Dev server

I had this work, I don’t remember what I changed, and now the page loads, but does not respond to the screen. I don’t know where the error is. No errors occur when I run webpack -m followed by npm start

the webapp folder looks like this ...

  • {app} - App.js
  • {} public - bundle.js - index.html
  • webpack.config.js
  • .babelrc
  • package.json

here are the important files

Webpack

module.exports = {
  entry: './app/App.js',
  output: {
    path: './public',
    filename: 'bundle.js',
  },
  devServer: {
      inline:true,
      contentBase: './public',
      port: 3333
    },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      }
    ]
  }
}

package.json

{
  "name": "newaccount",
  "version": "1.0.0",
  "description": "a form submission for new accounts",
  "main": "App.js",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "---",
  "license": "ISC",
  "dependencies": {
    "react": "^15.4.1",
    "react-dom": "^15.4.1",
    "react-router": "^3.0.0"
  },
  "devDependencies": {
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.8",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "html-webpack-plugin": "^2.24.1",
    "webpack": "^1.13.3",
    "webpack-dev-server": "^1.16.2"
  }
}

.babelrc

{
  "presets": [
          "es2015",
          "react"
    ]
}

App.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';



class Testing extends Component {
    render() {
        return (
            <div>
                <h3>JUST A TEST</h3>
            </div>
        )
    }
}

ReactDOM.render(<Testing />, document.getElementById('app'));

I have ever tried to do component testing ES6 const like ...

const Testing = () => return <div><h3>JUST A TEST</h3></div>

and still cannot get anything to be displayed on the local host: 3333 or the full path from my computer.

Thanks for any help

+4
source share
2 answers

, .

HTMLWebpackConfiguration webpack.config.js. index.html /app. , , HTML . webpack.config.js :

var HtmlWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
  template: __dirname + '/app/index.html',
  filename: 'index.html',
  inject: 'body'
});

module.exports = {
  entry: __dirname + '/app/App.js',
  output: {
    path: __dirname + '/public',
    filename: 'bundle.js',
  },
  plugins: [HTMLWebpackPluginConfig],
  devServer: {
      inline:true,
      contentBase: './public',
      port: 3333
    },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      }
    ]
  }
}

app/index.html :

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My App</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div id="app"></div>
</html>

:

https://tylermcginnis.com/react-js-tutorial-1-5-utilizing-webpack-and-babel-to-build-a-react-js-app-5f804d729d3b#.f4sslv7ub

: _registerComponent (...): DOM

http://javascriptplayground.com/blog/2016/07/webpack-html-plugin/

+2

. , .

webpack-dev-server , devServer webpack. , 7 . :

devServer: {
  contentBase: path.join(__dirname, "dist"),
  compress: true,
  port: 9000
}

, index.html ( ).

HTMLWebpackConfiguration .

https://webpack.js.org/configuration/dev-server/

+1

Source: https://habr.com/ru/post/1662911/


All Articles