Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 迁移 Preact #4

Open
jinjiaxing opened this issue Jan 8, 2018 · 0 comments
Open

React 迁移 Preact #4

jinjiaxing opened this issue Jan 8, 2018 · 0 comments

Comments

@jinjiaxing
Copy link
Owner

React 迁移 Preact

1:安装,preact preact-compat preact-redux

npm install preact preact-compat --save-dev
npm install preact-redux --save-dev

2:preact-compat的作用是让我们简单转换升级,只需简单修改代码适配即可

3: 设置 preact-compat 的 Alias,在webpack文件中:

    resolve: {
        alias: {
            // 'react': path.join(__dirname, 'node_modules', 'react')
            "react": "preact-compat",
            "react-dom": "preact-compat",
            // 如果代码使用了createClass,则加入下面
            'create-react-class': 'preact-compat/lib/create-react-class'
        },
    }, 

4:安装其他对应preact插件

npm install preact-tap-event-plugin --save-dev
(如果之前使用react-tap-event-plugin 则需要,没使用则不需要)

5:一键替换,只需要对应脚本即可

"dev": "NODE_ENV='dev' webpack-dev-server --config webpack.dev.config.js --watch --inline --compress --progress --colors --env development",
"dev:preact": "NODE_ENV='dev' REACT_ENV='preact' webpack-dev-server --config webpack.dev.config.js --watch --inline --compress --progress --colors --env development",
"release": "NODE_ENV='production' webpack --config webpack.release.config.js --display-error-details --progress --colors",
"release:preact": "NODE_ENV='production' REACT_ENV='preact' webpack --config webpack.release.config.js --display-error-details --progress --colors"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant