9.2.1 • Published 1 month ago

@nitro/webpack v9.2.1

Weekly downloads
278
License
MIT
Repository
-
Last release
1 month ago

npm version License Build Status

Nitro Webpack

Configurable and easy to use webpack 4 config for nitro projects.

Usage

const options = {
    rules: {
        js: true,
        ts: false,
        scss: true,
        hbs: true,
        woff: true,
        font: false,
        image: true,
    },
    features: {
        banner: true,
        bundleAnalyzer: false,
        theme: false,
        dynamicAlias: false,
    },
};
const webpackConfig = require('@nitro/webpack/webpack-config/webpack.config.dev')(options);

module.exports = webpackConfig;

Configuration

Rules

No loader rule is enabled by default. Activate following prepared rules you need in options.rules

options.rules.js

  • Type: boolean || object
  • default: false
  • file types: js, jsx, mjs

Config:

  • true or {} activates JavaScript support

options.rules.ts

  • Type: boolean
  • default: false
  • file types: ts, tsx

Config:

  • true will activate TypeScript support

options.rules.scss

  • Type: boolean || object
  • default: false
  • file types: scss, css

Config:

  • true or {} will activate scss support
  • { publicPath: '../' } provide a separate public path for stylesheets. By default, webpack uses the value from 'output.publicPath'. (only relevant for production build)
  • { implementation: require('node-sass') } gives the possibility to use 'node-sass' as sass implementation. (you have to add 'node-sass' as a dev-dependency in your project)

options.rules.hbs

  • Type: boolean || object
  • default: false
  • file types: hbs

Config:

  • true or {} will activate handlebars handlebars precompiled templates support
  • { include: [] } additionally adds include config to rule
  • { exclude: [] } additionally adds exclude config to rule

options.rules.woff

  • Type: boolean || object
  • default: false
  • file types: woff, woff2

Config:

  • true or {} will activate woff font support (in CSS files)
  • { include: [] } additionally adds include config to rule
  • { exclude: [] } additionally adds exclude config to rule

options.rules.font

  • type: boolean || object
  • default: false
  • file types: eot, svg, ttf, woff, woff2

Config:

  • true or {} will activate font support for eot, svg, ttf, woff & woff2 fonts (in CSS files)
  • { include: [] } additionally adds include config to rule
  • { exclude: [] } additionally adds exclude config to rule

⚠ Please use this rule with care. You have to configure includes and exclude when you also use woff and/or image loader. Otherwise, svg or woff files are processed with multiple configurations.

options.rules.image

  • Type: boolean || object
  • default: false
  • file types: png, jpg, gif, svg

Config:

  • true will activate image support
  • { include: [] } additionally adds include config to rule
  • { exclude: [] } additionally adds exclude config to rule

options.features

Enable some additional features

options.features.banner

  • Type: boolean
  • default: true

(only relevant for production build)

true will add a text banner with infos from package.json to the bundled js & css

options.features.bundleAnalyzer

  • Type: boolean
  • default: false

true will add the bundleAnalyser plugin and opens a browser window with the stats

options.features.theme

  • Type: string || false
  • default: false

A string will activate theming support:

  • webpack uses ./src/ui.${theme} as entrypoint (instead of ./src/ui)
  • a subfolder within assets is used for the output path and publicPath (/assets/${theme}/)

It makes sense to use a dynamic value e.g. an environment variable, as shown in the example configuration.

options.features.dynamicAlias

  • Type: object || false
  • default: false

A proper configured dynamicAlias feature will activate the DynamicAliasResolverPlugin which can change import paths in source files dynamically on compile time as desired.

Properties:

  • options.features.dynamicAlias.search (string || RegExp) search term to be replaced (e.g. '/theme/light')
  • options.features.dynamicAlias.replace (string) string as replacement (e.g. /theme/${theme})

Extending Configuration

Code Splitting

By default, all js imports from 'node_modules' are extracted to a 'vendors.js' to use in your view files.

Dynamically imported js files will be extracted to public/js/dynamic/. You may use them in a promise chain.

import('package-name').then((pack) => {
  // do something with 'pack'
});

import(
  /* webpackChunkName: "mychunk" */ 'package-name'
).then((pack) => {
  // do something with 'pack'
});

You may change the default configuration in webpackConfig.optimization.splitChunks

Changelog

Recent changes can be viewed on Github on the Releases Page

9.2.1

1 month ago

9.2.0

1 month ago

9.1.0

3 months ago

9.0.3

4 months ago

8.1.0

7 months ago

8.1.1

6 months ago

7.5.3

10 months ago

7.5.4

9 months ago

9.0.2

5 months ago

9.0.1

6 months ago

9.0.0

6 months ago

8.0.0

8 months ago

7.5.2

11 months ago

7.5.1

12 months ago

7.5.0

1 year ago

7.3.0

1 year ago

7.4.0

1 year ago

7.2.5

1 year ago

7.2.4

1 year ago

7.2.3

1 year ago

7.2.2

1 year ago

7.2.1

1 year ago

7.1.3

1 year ago

7.2.0

1 year ago

7.0.9

2 years ago

7.1.2

2 years ago

7.1.1

2 years ago

7.1.0

2 years ago

7.0.8

2 years ago

7.0.7

2 years ago

7.0.6

2 years ago

7.0.5

2 years ago

7.0.4

2 years ago

7.0.3

2 years ago

6.1.2

2 years ago

7.0.0

2 years ago

7.0.2

2 years ago

7.0.1

2 years ago

6.1.0

2 years ago

6.1.1

2 years ago

6.0.11

2 years ago

6.0.10

2 years ago

6.0.9

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

6.0.8

2 years ago

6.0.0-beta.4

2 years ago

6.0.0-rc.1

2 years ago

6.0.0-rc.3

2 years ago

6.0.0-rc.2

2 years ago

6.0.0-beta

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.5

2 years ago

6.0.4

2 years ago

5.10.17

2 years ago

5.10.16

3 years ago

5.10.15

3 years ago

5.10.14

3 years ago

5.10.13

3 years ago

5.10.12

3 years ago

5.10.11

3 years ago

5.10.10

3 years ago

5.10.9

3 years ago

5.10.8

3 years ago

5.10.7

3 years ago

5.10.6

3 years ago

5.10.5

3 years ago

5.9.2

3 years ago

5.10.0-beta.3

3 years ago

5.10.2-beta.0

3 years ago

5.10.4

3 years ago

5.10.3

3 years ago

5.10.2

3 years ago

5.10.1

3 years ago

5.10.0

3 years ago

5.10.0-beta.2

3 years ago

5.10.0-beta.1

3 years ago

5.9.1

3 years ago

5.9.0

3 years ago

5.8.9

3 years ago

5.8.8

3 years ago

5.8.7

3 years ago

5.8.6

3 years ago

5.8.5

3 years ago

5.8.4

3 years ago

5.8.3

3 years ago

5.8.2

3 years ago

5.8.1

3 years ago

5.8.0

3 years ago

5.7.5

3 years ago

5.7.4

3 years ago

5.7.3

3 years ago

5.7.2

3 years ago

5.7.1

3 years ago

5.7.0

3 years ago

5.6.12

4 years ago

5.6.11

4 years ago

5.6.10

4 years ago

5.6.9

4 years ago

5.6.8

4 years ago

5.6.7

4 years ago

5.6.6

4 years ago

5.6.5

4 years ago

5.6.4

4 years ago

5.6.3

4 years ago

5.6.2

4 years ago

5.6.1

4 years ago

5.6.0

4 years ago

5.5.3

4 years ago

5.5.2

4 years ago

5.5.1

4 years ago

5.5.0

4 years ago

5.4.0

4 years ago

5.3.3

4 years ago

5.3.2

4 years ago

5.3.1

4 years ago

5.3.0

4 years ago

5.2.9

4 years ago

5.2.8

4 years ago

5.2.7

4 years ago

5.2.6

4 years ago

5.2.5

4 years ago

5.2.4

4 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.6

4 years ago

5.1.5

4 years ago

5.1.4

4 years ago

5.1.3

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.14.4

4 years ago

5.0.0-rc.2

4 years ago

5.0.0-rc.1

4 years ago

5.0.0-beta

4 years ago

4.14.3

4 years ago

4.14.2

5 years ago

4.14.1

5 years ago

4.14.0

5 years ago

4.13.5

5 years ago

4.13.4

5 years ago

4.13.3

5 years ago

4.13.2

5 years ago

4.13.1

5 years ago

4.13.0

5 years ago

4.12.0

5 years ago

4.11.0

5 years ago

4.10.0

5 years ago

4.9.0

5 years ago

4.8.3

5 years ago

4.8.2

5 years ago

4.8.1

5 years ago

4.8.0

5 years ago

4.7.5

5 years ago

4.7.4

5 years ago

4.7.3

5 years ago

4.7.2

5 years ago

4.7.1

5 years ago

4.7.0

5 years ago

4.6.6

5 years ago

4.6.5

5 years ago

4.6.4

5 years ago

4.6.3

5 years ago

4.6.2

5 years ago

4.6.1

5 years ago

4.6.0

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.4

5 years ago

4.4.3

5 years ago

4.4.2

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.6

5 years ago

4.3.5

5 years ago

4.3.4

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.3

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.9

5 years ago

4.1.8

5 years ago

4.1.7

5 years ago

4.1.6

5 years ago

4.1.5

5 years ago

4.1.4

5 years ago

4.1.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago