1.0.0 • Published 3 years ago

webpack4-config-for-react v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

webpack4-config-for-react

webpack4-config-for-react is designed for different kinds of web app. It is based on create-react-app, but it's more flexible.

Installation

$ npx install-peerdeps -D webpack4-config-for-react

Usage

const createReactConfig = require('webpack4-config-for-react')

const config = createReactConfig({
  mode = process.env.NODE_ENV
})

API

createReactConfig.options:

  • webpack internal config
nametypedefaultdescription
modestring'development'see webpack mode
publicPathstring'./'see webpack publicPath
  • app path config
nametypedefaultdescription
appRootstring'.'the application's root dir
appSrcstring'./src'source code dir
appEntrystring'./src/index.js'source code entry file
appBuildstring'./dist'output dir after bundling
appPkgJsonstring'./package.json'package.json file path
appNodeModulesstring'./node_modules'dependency's dir
appHtmlstring'./public/index.html'the application's html file
appTsConfigstring'./tsconfig.json'tsconfig.json file path
swSrcstring'./src/service-worker'service worker dir
  • feature config
nametypedefaultdescription
useReactRefreshbooleanfalsewhether or not use @pmmmwh/react-refresh-webpack-plugin
useSourceMapbooleanfalsewhether or not use sourceMap
useTypescriptbooleanfalsewhether or not use typescript
useTsCheckbooleanfalsewhether or not check ts type
useInlineRuntimeChunkbooleantruewhether or not use react-dev-utils/InlineChunkHtmlPlugin
  • loader & plugin config
nametypedefaultdescription
imageInlineSizeLimitstring'10000'image inline size limit, see url-loader limit
interpolateHtmlPluginobject{ PUBLIC_URL: './' }new InterpolateHtmlPlugin(HtmlWebpackPlugin, interpolateHtmlPlugin)
definePluginobject{}DefinePlugin params
forkTsCheckerWebpackPluginobject{reportFiles: ['../**/src/**/*.{ts,tsx}','**/src/**/*.{ts,tsx}','!**/src/**/__tests__/**','!**/src/**/?(*.)(spec\|test).*',]}react-dev-utils/ForkTsCheckerWebpackPlugin params, only valid when useTypescript and useTsCheck are enabled
  • other
nametypedefaultdescription
appNamestring'app'the application's name

Caveats

You have to set process.env.NODE_ENV by yourself, cause babel needs process.env.NODE_ENV not undefined.