react(16.9) + antd4.x + webpack4.0 + eslint + typeScript + less
// 开发环境启动
npm run start 或者 yarn start
// 生产环境打包
npm run build 或者 yarn build
npm init -y
npm install typescript purgecss-webpack-plugin glob @babel/preset-react @babel/preset-typescript copy-webpack-plugin @babel/plugin-transform-runtime @babel/runtime core-js@2 @babel/plugin-proposal-class-properties @babel/plugin-proposal-decorators @babel/core @babel/preset-env babel-loader url-loader file-loader optimize-css-assets-webpack-plugin terser-webpack-plugin postcss-loader autoprefixer less-loader less style-loader css-loader mini-css-extract-plugin webpack webpack-cli webpack-dev-server webpack-merge html-webpack-plugin html-webpack-plugin clean-webpack-plugin add-asset-html-webpack-plugin --save-dev
npm i @types/react @types/react-dom -D
npm i react react-dom antd @ant-design/icons -S
npm i eslint-config-airbnb-typescript eslint eslint-loader eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y --D
npm i @typescript-eslint/parser @typescript-eslint/eslint-plugin -D
npm i cross-env babel-plugin-import -D
npm i dva dva-model-extend dva-loading antd immer lodash moment nprogress prop-types qs query-string path-to-regexp @ant-design/icons axios -S
new PurgeCssWebpackPlugin({
paths: glob.sync("./src/**/*", {
nodir: true
})
}),
在css模块化时使用这个插件去除css无用代码时,没有将css中无用的的样式全部删除掉,目前没有找到解决方式
-
解决
-
使用babel-plugin-dva-hmr
yarn add babel-plugin-dva-hmr redbox-react --dev
.babelrc
{ "plugins": ["dva-hmr"] }
a.js
export type A = any
const fn = () => {}
export default fn
b.js
import fn, { A } from './a.js'
export {
fn,
A,
}
// 这样b.js会报警告
"export 'A' was not found in './a'
{/* <div>{{}}</div> */}
这样的错误在浏览器不显示,只有在控制台中才能看到
patch-package yarn add patch-package postinstall-postinstall
参考官网进行配置
yarn add hard-source-webpack-plugin --dev