1.9.17 • Published 6 months ago

@pplancq/webpack-config v1.9.17

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@pplancq/webpack-config

This package has been designed to provide a simplified and customisable Webpack configuration for React applications. Whether you're a beginner or an experienced developer, this package will allow you to configure your development environment quickly and efficiently, while giving you the flexibility to tailor the configuration to your specific needs.

Getting Started

Prerequisites

  • node 18.12.0 or higher

Install

npm install --save-dev @pplancq/webpack-config webpack webpack-cli webpack-dev-server

Usage

To enable the default configuration, use the following command

npx init-webpack-config

Add an entry point file src/main.ts or src/main.js and a template HTML file in public/index.html.

Commands

  • Starts the development server
npm run start

or

webpack serve
  • Build the application
npm run build

or

webpack --mode production

Functionalities

This configuration includes the following:

  • JavaScript/TypeScript files: Uses swc-loader.
  • CSS files: Uses css-loader and postcss-loader with modules option enabled (see CSS/SCSS Modules).
  • SCSS/SASS files: Uses sass-loader with modules option enabled (see CSS/SCSS Modules).
  • Image or font files: Uses asset/resource type of Webpack 5.
  • SVG files: Uses asset/resource type of Webpack 5 or @svgr/webpack (see SVG Files).

CSS/SCSS Modules

This package supports CSS and SCSS modules, allowing you to scope your styles locally to avoid conflicts and ensure maintainability.

Usage

To use CSS or SCSS modules, follow these steps

  1. Create a CSS/SCSS module file
    • For CSS: styles.module.css
    • For SCSS: styles.module.scss
  2. Import the module in your JavaScript/TypeScript file
import styles from './styles.module.css';
import styles from './styles.module.scss';
  1. Apply the styles to your components
export const MyComponent = () => {
  return (
    <div className={styles.myClass}>
      <p className={styles.myParagraph}>Hello, World!</p>
    </div>
  );
};

SVG Files

Two configurations are available for SVG files:

  1. Import as a resource: This allows you to use SVG files via the <img/> tag.
import svgFile from './file.svg';

export const MyComponent = () => {
  return <img src={svgFile} />;
};
  1. Import as a React component
import SvgComponent from './file.svg?react';

export const MyComponent = () => {
  return <SvgComponent />;
};

Environment Variables

For all environments, the following files are loaded if they exist, with later ones taking precedence over earlier ones:

  • .env contains default values for environment variables required by the application.
  • .env.local allows overwriting environment variables (unversioned file).
  • .env.<MODE> contains environment-specific variables.
  • .env.<MODE>.local overwrites environment-specific variables (unversioned file).

<MODE> available by default: development, production, or test.

Real system environment variables take precedence over .env files.

Default environment variables

VariableDefaultDescription
BROWSERfalseEnables/disables launching the browser when npm start is run.
PORT3000Sets the port for the development web server.
DISABLE_STYLELINT_PLUGINfalseAllows you to deactivate the stylelint plugin
DISABLE_ESLINT_PLUGINfalseAllows you to deactivate the eslint plugin
ESLINT_CONFIG_TYPEeslintrcSpecify the type of configuration to use with ESLint.- 'eslintrc' is the classic configuration format available in most ESLint versions. - 'flat' is the new format introduced in ESLint 8.21.0.
DISABLE_SOURCE_MAPfalseAllows you to deactivate the sourcemap
PUBLIC_URLhttp://localhost/Sets the public URL or path for production environment.
ENV_PREFIXFRONT_Sets the prefix for environment variables that will be passed to the frontend.Access environment variables using import.meta.env.FRONT_FOO in the code.

Caution with Environment Variables

The webpack configuration of this project allows for environment variables to be included in the application bundle. This could potentially expose sensitive information if the bundle is publicly accessible.

It is recommended to only include non-sensitive environment variables in the application bundle. Sensitive information should not be exposed even if the bundle is publicly accessible.

Ensure you understand the security implications before including environment variables in your bundle.

Please note that the web configuration pre-filters environment variables via the default prefix ‘FRONT’. This means that only environment variables starting with ‘FRONT’ will be included in the bundle. This is an additional layer of security to prevent the accidental exposure of sensitive environment variables.

1.9.1

10 months ago

1.8.2

12 months ago

1.9.0

10 months ago

1.8.1

12 months ago

1.8.0

12 months ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.9.17

6 months ago

1.9.16

6 months ago

1.9.15

6 months ago

1.9.14

6 months ago

1.9.13

7 months ago

1.9.12

7 months ago

1.9.11

7 months ago

1.9.10

8 months ago

1.9.9

8 months ago

1.9.8

8 months ago

1.9.7

8 months ago

1.9.6

9 months ago

1.9.5

9 months ago

1.9.4

9 months ago

1.8.5

10 months ago

1.9.3

9 months ago

1.8.4

11 months ago

1.9.2

9 months ago

1.8.3

11 months ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago