In this template I use webpack, it contains plugins for optimize, split the code, and minify the better than I could. It also removes the data-test-id for react components (for a better production mode). Compress the javascript files that are result of the building in gzip algorithm. Make aliases from all paths using @/path/ from src directory, load javascript files as modules for unblocking the page loading. Minify SCSS and CSS, including css modules. For the code splitting, webpack tries to split all the code with a max size of 124000 Bytes, and for react, it minify, or less it tries, to split all the code as can be possible.
Explanation:
- Entry (entry file of the project)
- output (the output path)
- path: resolve(...) (Allow us set the output directory)
- filename: [name].[fullhash].js (Transpile all the files specified in resolve and module.rules)
- clean: true (Delete the dist repository before to re-build)
- publicPath: '/' (Set the public path as the root of the project)
- Resolve (Configuration for the files who will be checked)
- extensions: ['.ts', '.tsx', '.js']
- alias : {...} (Set aliases, they can be used in the code as the example below)
- import Main from "@src/component"
- Plugins
- MiniCssExtract (Extract the css from the js files)
- HtmlPlugin (set the html template to use)
- scriptLoading: module (set the type="" in script tag 'module' is used for performance)
- template: '/../index.html' (set where is the template and the name)
- minify: true (minify html)
- Compression (gzip all the files builded that match the test)
- test: *js (All js files compressed)
- filename: [name].js.gz (All files have this name structure) 3. algorithm: gzip (Compresssion algorithm to use)
- module.rules (parse the files to be loaded from webpack)
- SCSS.modules: true (it allow us use the *.module.scss syntax in jsx)
- TS-loader.configFile (set the tsconfig file)
- TS-loader.removeDataTestId (Remove the data-testid from the react components (for prod mode))
- Optimization
- chunksIds: named (the algorithm webpack use to choose to call the chunks)
- moduleIds: named (Which algorithm will be used by webpack for choose module ids)
- mangleExports: size (Module names (1 character))
- portableRecords: true (Relative paths for be able to move this project)
- minimize: true (minimze all the bundles)
- minimizer: these plugins minize the bundles
- splitChunks (Split all the code that can be possible)
- chunks: all (Select all chunks will be optimized);
- maxAsyncRequests: 30 (Maximum parallel request)
- minSize: 10000 (Min chunk size, in bytes)
- maxSize: 124000 (Try to split the modules greatter than 124000 bytes)
- cacheGroups
- reactVendor (Cache group)
- test: .. (controll what modules are in this cache group)
- name: 'vendor-react' (name for chunk files)
- maxSize: 140000 (maxSize of the chunk files)
- performance
- hints: 'warning' (Show a warning when the files configured here are bigger than the configuration)
Jest uses typescript and I test that is enough for futures implementations. It uses ts-jest for parsing the
tsx files to js files for testing. It need to use jsdom by default because we are using a browser implementation.
It also uses alias, @src/(.*): ...
implements aliases for jest. (using also the tsconfig file). And css|scss mapper is for *.module.s?css files.
And select the babelConfig to false for not usign babel.
The last important theme about this template, is we use express for serve the files. But when we make a query of a dot js file, express sends a gzip module, for optimize the loading of them.
If you want to implement my git hooks, please put this command:
git config core.hooksPath .githooks