插件/预设文件不允许导出对象,仅可使用React版本16.4的功能

时间:2018-09-01 23:22:52

标签: reactjs

尝试构建npm run watch时出现此错误-

这是我的webpack.config

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

const htmlPlugin = new HtmlWebPackPlugin({
  template: "./src/index.html",
  filename: "./index.html"
});

module.exports = {
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index_bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader']
      }
    ]
  },
  plugins: [htmlPlugin]
};

package.json

const webpack = require('webpack');
const config = {
    entry:  __dirname + '/js/index.jsx',
    output: {
        path: __dirname + '/dist',
        filename: 'bundle.js',
    },
    resolve: {
        extensions: ['.js', '.jsx', '.css']
    },
    module: {
      rules: [
        {
          test: /\.jsx?/,
          exclude: /node_modules/,
          use: [
          {
          loader: 'babel-loader',
          options: {
                 presets: ['react']
                }
            }
          ]

        }
      ]
    },

};
module.exports = config;

index.html

{
  "name": "flask-react-app",
  "version": "1.0.0",
  "description": "This is a simple flast react integration app.",
  "main": "index.js",
  "scripts": {
    "build": "webpack -p --progress --config webpack.config.js",
    "dev-build": "webpack --progress -d --config webpack.config.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "webpack --progress -d --config webpack.config.js --watch"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "react-dom": "^16.4.2",
    "webpack": "^4.17.1",
    "webpack-cli": "^3.1.0"
  }
}

App.js

<html>
  <head>
    <meta charset="utf-8">
    <!-- Latest compiled and minified bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
    <title>Creating a Full-Stack Python Application with NPM, React.js and Webpack</title>
  </head>
  <body>
    <div id="content" />
    <script src="dist/bundle.js" type="text/babel"></script>
  </body>
</html>

index.jsx

import React from “react”;
export default class App extends React.Component {
  render () {
    return <p> Hello React!</p>;
  }
}

0 个答案:

没有答案