从样板(反应)项目中删除服务器端

时间:2018-12-17 08:55:49

标签: javascript node.js reactjs express react-redux

我已经克隆并安装了https://github.com/react-boilerplate/react-boilerplate项目,但是我只需要项目的客户端,因为我将使用另一个已经创建的服务器(快速)。     这是我的package.json

.css("visibility", "visible")

这是我文件的项目结构:[在此处输入图像描述] [1]

<code>


  "scripts": {  enter code here
       "analyze:clean":"rimraf stats.json",
       "preanalyze":"npm run analyze:clean",
       "analyze":"node ./internals/scripts/analyze.js",
       "extract-intl":"node ./internals/scripts/extract-intl.js",
       "npmcheckversion":"node ./internals/scripts/npmcheckversion.js",
       "preinstall":"npm run npmcheckversion",
       "prebuild":"npm run build:clean",
       "build":"cross-env NODE_ENV=production webpack --config internals/webpack/webpack.prod.babel.js --color -p --progress --hide-modules --display-optimization-bailout",
       "build:clean":"rimraf ./build",
       "start":"cross-env NODE_ENV=development node server",
       "start:tunnel":"cross-env NODE_ENV=development ENABLE_TUNNEL=true node server",
       "start:production":"npm run test && npm run build && npm run start:prod",
       "start:prod":"cross-env NODE_ENV=production node server",
       "presetup":"npm i chalk shelljs"
    }
</code>    

2 个答案:

答案 0 :(得分:0)

将此代码用于Package.json。用于带有webpack,Redux和babel的简单CSR React项目。

{
  "name": "startup",
  "version": "0.1.0",
  "private": true,
  "homepage": "http://localhost:3000",
  "dependencies": {
    "@babel/polyfill": "^7.7.0",
    "axios": "^0.19.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "env-cmd": "^10.0.1",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-data-components": "^1.2.0",
    "react-dom": "^16.8.6",
    "react-hot-loader": "^4.12.18",
    "react-redux": "^7.1.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1",
    "redux": "^4.0.4",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.1.3",
    "styled-components": "^4.4.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.6",
    "babel-plugin-lodash": "^3.3.2",
    "babel-plugin-react-transform": "^3.0.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "clean-webpack-plugin": "^3.0.0",
    "html-webpack-plugin": "^3.2.0",
    "prettier": "1.19.1",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.9.0"
  },
  "scripts": {
    "dev": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

并使用它来配置webpack,将以下代码添加到新的/现有的webpack.config.js中,以为prod-build和dev(localhost)运行代码。

const path = require('path');
const HWP = require('html-webpack-plugin');
const webpack = require('webpack');
require("@babel/polyfill");
var node_modules_dir = path.resolve(__dirname, 'node_modules');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
    entry: ['babel-polyfill', './src/index.js'],
    output: {
        filename: 'build.js',
        path: path.join(__dirname, '/dist/')
    },
    optimization: {
        splitChunks: {
          // include all types of chunks
          chunks: 'all'
        }
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            exclude: node_modules_dir,
            loader: 'babel-loader',
            query: {                    
                plugins: ['transform-class-properties']
            }
        }, {
            test: /\.*css$/,
            use: ['style-loader', 'css-loader']

        }, {
            test: /.(png|jpe?g|gif|svg|ico)$/,
            use: 'file-loader?name=assets/images/[hash].[ext]'
        }, {
            test: /.(woff|woff2|otf|ttf|eot)$/,
            use: 'file-loader?name=assets/fonts/[hash].[ext]'
        }]
    },
    devServer: {
        publicPath: '/',
        historyApiFallback: true,
    },
    plugins: [
        new CleanWebpackPlugin(),
        new webpack.ProgressPlugin(),
        new HWP({
            template: './src/index.html',
            filename: 'index.html'
        })
    ]
}

答案 1 :(得分:0)

如果您只需要从头开始一个前端react项目,则可以使用,Object.assign工具创建一个。

如果是,只需使用这样的工具

create-react-app