# @lorndev/webpack-core

> Provide webpack default sources (pulling core auto)

Latest version **1.0.13** (published 2021-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @lorndev/webpack-core
pnpm add @lorndev/webpack-core
yarn add @lorndev/webpack-core
bun add @lorndev/webpack-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2021-01-14 |
| First published | 2020-06-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 40 |
| Unpacked size | 41.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Paul Weinsberg |
| Maintainers | lorndev |

## Links

- npm: https://www.npmjs.com/package/@lorndev/webpack-core
- Repository: https://github.com/PaulWeinsberg/webpack-core
- Homepage: https://github.com/PaulWeinsberg/webpack-core#readme
- Issues: https://github.com/PaulWeinsberg/webpack-core/issues
- npm.io page: https://npm.io/package/@lorndev/webpack-core

## Dependencies (40)

- [react](https://npm.io/package/react.md) ^16.14.0
- [eslint](https://npm.io/package/eslint.md) ^6.8.0
- [core-js](https://npm.io/package/core-js.md) ^3.8.1
- [cssnano](https://npm.io/package/cssnano.md) ^4.1.10
- [webpack](https://npm.io/package/webpack.md) ^4.44.1
- [node-sass](https://npm.io/package/node-sass.md) ^4.14.1
- [react-dom](https://npm.io/package/react-dom.md) ^17.0.1
- [ts-loader](https://npm.io/package/ts-loader.md) ^6.2.1
- [css-loader](https://npm.io/package/css-loader.md) ^3.6.0
- [typescript](https://npm.io/package/typescript.md) ^3.9.7
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.11.0
- [file-loader](https://npm.io/package/file-loader.md) ^5.1.0
- [sass-loader](https://npm.io/package/sass-loader.md) ^8.0.2
- [webpack-cli](https://npm.io/package/webpack-cli.md) ^3.3.12
- [@types/react](https://npm.io/package/@types/react.md) ^16.14.2
- [autoprefixer](https://npm.io/package/autoprefixer.md) ^9.8.6
- [babel-loader](https://npm.io/package/babel-loader.md) ^8.0.6
- [browser-sync](https://npm.io/package/browser-sync.md) ^2.26.12
- [eslint-loader](https://npm.io/package/eslint-loader.md) ^3.0.3
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.12.5
- [extract-loader](https://npm.io/package/extract-loader.md) ^4.0.3
- [postcss-loader](https://npm.io/package/postcss-loader.md) ^3.0.0
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^17.0.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.11.0
- [svg-inline-loader](https://npm.io/package/svg-inline-loader.md) ^0.8.2
- [eslint-plugin-node](https://npm.io/package/eslint-plugin-node.md) ^11.0.0
- [postcss-inline-svg](https://npm.io/package/postcss-inline-svg.md) ^4.1.0
- [postcss-preset-env](https://npm.io/package/postcss-preset-env.md) ^6.7.0
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.12.10
- [copy-webpack-plugin](https://npm.io/package/copy-webpack-plugin.md) ^5.1.1
- [eslint-plugin-react](https://npm.io/package/eslint-plugin-react.md) ^7.20.5
- [clean-webpack-plugin](https://npm.io/package/clean-webpack-plugin.md) ^3.0.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.22.0
- [eslint-plugin-promise](https://npm.io/package/eslint-plugin-promise.md) ^4.2.1
- [eslint-plugin-standard](https://npm.io/package/eslint-plugin-standard.md) ^4.0.1
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) ^2.34.0
- [browser-sync-webpack-plugin](https://npm.io/package/browser-sync-webpack-plugin.md) ^2.2.2
- [webpack-fix-style-only-entries](https://npm.io/package/webpack-fix-style-only-entries.md) ^0.4.0
- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.12.10
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) ^2.34.0

## Recent versions

- 1.0.13 (latest) — 2021-01-14
- 1.0.12 — 2021-01-14
- 1.0.11 — 2021-01-14
- 1.0.10 — 2021-01-14
- 1.1.0 — 2020-12-21
- 1.0.9 — 2020-12-15
- 1.0.8 — 2020-12-12
- 1.0.7 — 2020-10-06
- 1.0.6 — 2020-10-06
- 1.0.5 — 2020-10-06
- 1.0.4 — 2020-08-03
- 1.0.3 — 2020-06-23
- 1.0.2 — 2020-06-23
- 1.0.1 — 2020-06-23
- 1.0.0 — 2020-06-19

## README

# WEBPACK Vanksen v1.0.3

Brand new front distribution to use JS6, TypeScript with new features and still compatible with old browsers.

## Overview

### Features

| Feature                   | Informations                                                                    |
| ------------------------- | ------------------------------------------------------------------------------- |
| Webpack 4                 | Base functionnalities (compile, import/export behavior, create bundle etc...)   |
| Babel                     | Mapped to .browserslinkrc to target desired output EcmaScript version           |
| Typescript                | TypeScript compiler, use babel after compilation (JS and TS consistency)        |
| Sass                      | Transform your SCSS stylesheets to standard CSS                                 |
| PostCSS                   | Concact and organize CSS, mapped with .browserslinkrc like Babel                |
| Autoprefixer              | Autoprefix your CSS for many browsers                                           |
| CSSNano                   | Minify your CSS (minify base64 and svg inlined string, global minifying)        |
| SVG Inline                | Minify SVG outputed files                                                       |
| ESLint                    | JavaScript/TS linter, make your project sane and robust                         |

### Requirements

| Dependencies              | Version                   |
| ------------------------- | ------------------------- |
| NPM                       | v6.13                     |
| NodeJS                    | v12.18                    |

### Files structure

#### This package

```ini
node_modules/@lorndev/webpack-core
├── .babelrc                  # Babel configuration (Typescript and JS files)
├── .browserslistrc           # Browserslist need to works with your project (used by Babel, PostCSS)
├── .eslintrc                 # ESLint configuration, warns only as default
├── postcss.config.js         # Export modules for PostCSS configuration
├── tsconfig.json             # TypeScript configuration
├── config.default.json       # Common configuration (shared with dev and prod, also your main configuration file)
├── webpack.dev.config.js     # Developement mode webpack configuration
└── webpack.build.config.js   # Production mode webpack configuration

# (package.json, .editorconfig...)
```

#### Sources folder (`<project_root>/.webpack` for example)

Your src folder need to be a copy of src_default to start your project.

```ini
src
├── config.json               # Override config.default.json, same function
├── distribution              # Contain project distribution (Not exported at build can only serve dependencies like sass mixins etc)
└── public                    # Exported dir into project public root (for example public dir is ./web for Drupal 8)

# (package.json, .editorconfig, .git, node_modules ...)
```

## Getting Started

Starting your project from skratch easyly !

### Installation

First step install or create your project root dependencies (Drupal, Symfony, Sylius as you want..).
Now, is recommanded to use files structure explain above, so :

Note : You can use a preconfigured webpack sources here : [webpack preconfigured sources](https://gitlab.com/vanksen/front/webpack)

* Create a folder which contain your sources (`.webpack` for example)
* Run in console npm install `@lorndev/webpack-core`
* Run `npm install`
* Copying `config.default.json` at root of `.webpack` and rename as `config.json`
* Setup your configuration
* Create run scripts in your `package.json` as below :

```json
{
// code ...
  "scripts": {
    "build": "webpack --config=node_modules/@lorndev/webpack-core/webpack.build.config.js",
    "dev": "webpack --config=node_modules/@lorndev/webpack-core/webpack.dev.config.js"
  }
// code ...
}
```

You're ready to use it.


### Configuration

Your main configuration is in your sources folder, `config.json`, this file override `config.default.json`.

__Take that into consideration :__

Base configuration is an example for Drupal website which has theme named vanksen.
For drupal public folder is `<project_root>/web`, so this is your mapped dir with `<project_root>/.webpack/public` folder and it's mapped with `/` website route.
Remember, your configuration paths **is relative from npm script running folder** in this case `<project_root>/.webpack`.

#### Common configuration

Webpack Vanksen provide a configuration file which is loaded by Webpack production and development mode.
In most of the cases, this is your only configuration file you need to edit.
See comments below for more informations :

```js
{
  "src": "public",                                                    // Source public path, need to math with public dist
  "dist": "../web",                                                   // Dist public path
  "publicPath": "/",                                                  // Dist root route (to resolve required files from compiled JS)
  "chunkDir": "themes/custom/vanksen/chunks",                         // Your chunks directory, each dynamic import create a chunk js file
  "compileExtensions": [".js",".ts",".scss",".svg"],                  // Extensions to use as entries, webpack compile it with associated loaders
  "resolveExtensions": [".js",".ts",".sass",".tsx",".jsx",".json"],   // Resolve path in extensions (import, export, url functionnalities...)
  "extractExtensions": ["css","scss","svg"],                          // Extracted from bundle (example: create .css files not style tag in JS)
  "exclude": "/(node_modules|bower_components)/",                     // Excluded from webpack parsing without calling with import
  "browserSync": {
    "network": {
      "host": "localhost",                                            // BrowserSync host
      "proxy": "vanksen.docksal",                                     // BrowserSync proxy (your local project url)
      "port": 4200,                                                   // BrowserSync port
      "ui": { "port": 4201 },                                         // BrowserSync ui port
      "open": false                                                   // Open browser on build
    },
    "options": {
      "injectCss": true                                               // Inject CSS without page reload
    }
  },
  "sass": {
    "includePaths": [                                                 // Sass included path to resolve it without full or relative url
      "distribution/sass",
    ]
  },
  "copy": {
    "ignore": ["*.ts","*.js","*.scss",".svg",".gitkeep"]              // When your build is finalized, webpack copying all files from src to dist
  },
  "clean": {
    "beforeBuild": ["../web/**/*chunk.js"],                           // Before build, removing matched files
    "afterBuild": []                                                  // After build, removing matched files
  },
  "stats": {                                                          // Webpack output, see webpack documentation for more informations
    "all": false,
    "errors": true,
    "errorDetails": true,
    "warnings": true,
    "performance": true,
    "timings": true,
    "builtAt": true,
    "publicPath": true,
    "outputPath": true
  }
}
```


#### Configure specific mode

Webpack provide two mode as default : production and development.

- Webpack production mode default configuration : [production mode]()
- Webpack development mode default configuration : [development mode]()

This distribution use both configurations, which is loaded by :

- Production : `webpack.dev.config.js`
- Development : `webpack.build.config.js`

It's not recommanded to edit both files before, but it's a possibility if it's realy necessary.
For more information, visit webpack documentation here : [Webpack documentation]()

### Usages

First step, run `npm install`

#### Production and development

Easy to use :

- `npm run dev` : Development
- `npm run build` Production

#### Entries & bundle

**Understanding**

Webpack Vanksen distribution override default Webpack behavior.
As default Webpack use few entries and generate CSS, chunks and other file in unique bundle file.
The Vanksen distribution extract assets like CSS, SVG and others files to increase performance and provide a distribution which can used with a lot of frameworks and tools.
To make it, Webpack is configured to parse your public repository and use assets as bundle but not generate useless bundle file.
For example : Your CSS is used as entry, but only SVG file is extracted and Webpack do not create a bundle file for this entry.

**Use bundle functionnality**

All files not prefixed by underscore is a bundle, webpack integrate static imports and others depencencies in the generated bundle.
So, use underscore `_` to specify if your file is a dependency.

For example :

`public/_dependency.ts`

```typescript
export class Example {

  private message: string;

  public constructor () {
    this.message = 'Hello World !';
  }

  public displayMessage() {
    return console.log(this.message);
  }
}
```

`public/mybundle.ts`
```typescript
import { Example } from './_dependency';

new Example().displayMessage();
```

In this example, webpack generate a file ( `mybundle.js` the bundle) which contain example class and code of `mybundle.ts`.

**Use dynamic imports**

The dynamic import works different, the imported class isn't integrated in the bundled file but a chunks with specific id is generated.
So, when the dynamic import function is called, the chunk file is automatically added to JS file in browser.

For example, to dynamically import bootstrap from `node_modules` :

`public/mybundle.ts`
```typescript
setTimeout(() => {
  import('bootstrap').then(bootstrap => console.log(bootstrap));
},3000)
```

---
_Source: https://npm.io/package/@lorndev/webpack-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
