如果使用 ykit 构建项目,可以在 modifyWebpackConfig
中配置 alias
来使用 qreact
替换 react
和 react-dom
:
module.exports = {
/*
...
*/
config: {
modifyWebpackConfig: function(baseConfig) {
// 其他 webpack 配置
baseConfig.resolve = {
alias: {
react: 'qreact',
'react-dom': 'qreact',
// 若要兼容 IE 请使用以下配置
// 'react': 'qreact/dist/ReactIE',
// 'react-dom': 'qreact/dist/ReactIE',
// 如果需要在 IE 下使用redux
// 建议使用 QReact 提供的 ReduxIE 来减少性能损耗
// 'redux': 'qreact/lib/ReduxIE',
// 如果引用了 prop-types 或 create-react-class
// 需要添加如下别名
// 建议加上这两条,因为即使项目代码中没有用到
// 第三方代码也可能会用到
'prop-types': 'qreact/lib/ReactPropTypes',
'create-react-class': 'qreact/lib/createClass',
// 如果使用了 react-tap-event-plugin
// 移动端项目(比如 yo)请务必加上此条
'react-tap-event-plugin': 'qreact/lib/injectTapEventPlugin.js'
}
};
return baseConfig;
}
}
/*
...
*/
};