Skip to content

Instantly share code, notes, and snippets.

@darkcar
Last active September 24, 2019 05:43
Show Gist options
  • Save darkcar/d3432aa873884125d928d1ca8fe58d1f to your computer and use it in GitHub Desktop.
Save darkcar/d3432aa873884125d928d1ca8fe58d1f to your computer and use it in GitHub Desktop.
react

Webpack

npm init -y

mkdir src dist

npm i webpack -D

npm i webpack-cli -D

NodeJS 视频, 完成第一天


For multiple nodeJS version, use this management tool: nvm

NodeJS no need for a webserver.

REPL: Read-Eval-Print-Loop交互式解释器

Modules

  • process: global module
  • fs: non-global module

NodeJS中的IO是单线程,非阻塞的。


__dirname: 当前js文件所在的目录

__filename:表示当前正在执行的js文件的完整路径


error-first: callback function, the first parameter is alway err object.


Use nodejs to create a webserver

React

Steps to setup React environment

  • Install react react-dom dependencies

    npm i -S react react-dom // Use these packages until production
    • react: create components and virtual dom.
    • react-dom: dom manipulation and display, mainly used ReactDOM.render()
  • Use two important functions:

    import React from 'react';
    import ReactDOM from 'react-dom';
    
    const myDiv = React.createElement('div', null, 'This is a div');
    ReactDOM.render(myDiv, document.getElementById('app'));
    
  • To write JSX syntax statements, we need to install Babel in our dev system.

    npm i -D babel-core babel-loader babel-plugin-transform-runtime 
    npm i -D babel-preset-env babel-preset-stage-0
    
    // Convert JSX syntax package 
    npm i -D babel-preset-react 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment