• react前端自动化webpack配置


    1. npm init
    2. package.json install dependence
    webpack webpack-dev-server
    react react-dom react-hot-loader
    css-loader style-loader
    babel babelify babel-loader babel-core babel-preset-es2015 babel-preset-react

    script start : webpack-dev-server

    3. webpack.config.js
    require resolve from path

    entry : /src/js/index.js
    output : /dist/main.js
    module /.js$/ loader:babel-loader query:presets:[es2015,react]

    devServer :hot contentBase

    plugins : new webpack.HotModuleReplacementPlugin()

    webpack-dev-server 

    目录结构:

    4. react component

    生产component

    export default class headerComponent extends React.Component{
        render(){
            return (
                <header>
                    this is a header
                </header>
            )
        }
    }
    

     并入index.js

    import HeaderComponent from './components/header.component.js'
    class Index extends React.Component{
        render(){
            return (
                <div>  
                    <HeaderComponent></HeaderComponent>
                    <Container></Container>
                    <FooterComponent></FooterComponent>
                </div>
            )
        }
    }

     渲染到index.html

    ReactDom.render(
        <Index></Index>,
        document.getElementById('example')
    )

     5. 样式引用

    style-loader和css-loader

    main.css新建样式

    .small-font{
        background: #123;
        color:#fff;
        font-size: 12px;
    }

     组件引用

                <header className='small-font'>
                    this is a header
                </header>    

     创建样式对象

            const headerStyle = {
                background:'#333'
            }    

     引入样式对象,此时会编译为行内样式

    <header style={headerStyle} className='small-font'>
            this is a header
    </header>

    6 state props

      1. state控制组件的状态,props进行组件传参

      2. state改变可以迅速反应到dom上,进行虚拟virtual dom渲染,setState进行传

  • 相关阅读:
    Spark笔记
    java.lang.ClassNotFoundException: org.apache.storm.topology.IRichSpout
    异常分类
    手动调用run方法和普通方法调用没有区别
    URI is not registered ( Setting | Project Settings | Schemas and DTDs )
    谷歌浏览器远程计算机或设备将不接受连接解决方法
    模块2复习
    day09作业01用户登录与验证
    022测试对文档进行读取与写入
    0221判断登录是否成功小程序
  • 原文地址:https://www.cnblogs.com/sowhite/p/6834335.html
Copyright © 2020-2023  润新知