Js 前端

Node Npm


# https://nodejs.org/en/

sudo npm install npm -g
sudo npm install npm@latest -g

sudo npm install -g n

sudo n latest
sudo n stable
sudo n lts

Angular

npm install -g @angular/cli
ng new hello
cd hello
ng serve
ng serve --open
ng g component hello
ng g component hello  -it -is --spec=false
ng g service hello
ng g module app-routing --flat --module=app
ng g directive hello

cli

Create-react-app

npx create-react-app hello

sudo npm install -g create-react-app
create-react-app hello

React-app-rewired

/* config-overrides.js */

module.exports = function override(config, env) {
  //do stuff with the webpack config...
  return config;
}

npm install react-app-rewired --save-dev

# change node_modules/react-app-rewired/scripts/start.js  $webpackConfigPath

React-Script React-app-rewired Mocker-api

npm install mocker-api --save-dev

vi mock/index.js

module.exports = {
  'GET /api/profile': {
    name: 'Test',
    userid: 10001,
  },

  'POST /api/register': (req, res) => {
    res.send({
      status: 200,
      statusText: 'ok'
    });
  },
};

vi config-overrides.js

const path = require("path");
const apiMocker = require('mocker-api');

const override = {
    webpack(config, env) {
        return config;
    },
    devServer(configFunction) {
        return (proxy, allowedHost) => {
            let config = configFunction(proxy, allowedHost);
            let before = config.before;
            config.before = (app, server) => {
                apiMocker(app, path.resolve('./mock/index.js'), {
                    proxy: {
                        '/repos/*': 'https://api.github.com/',
                    },
                    changeHost: true,
                });
                before(app, server);
            }
            return config;
        };
    }
}

module.exports = override;

posted @ 2018-12-29 14:23  fr5s  阅读(135)  评论(0编辑  收藏  举报