npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pplancq/webpack-config

v1.7.0

Published

pplancq webpack config

Downloads

198

Readme

@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

| Variable | Default | Description | | ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | BROWSER | false | Enables/disables launching the browser when npm start is run. | | PORT | 3000 | Sets the port for the development web server. | | DISABLE_STYLELINT_PLUGIN | false | Allows you to deactivate the stylelint plugin | | DISABLE_ESLINT_PLUGIN | false | Allows you to deactivate the eslint plugin | | ESLINT_CONFIG_TYPE | eslintrc | Specify 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_MAP | false | Allows you to deactivate the sourcemap | | ENV_PREFIX | FRONT_ | 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.