# @ifreeworld/webpack-config

> 通用的 webpack 配置

Latest version **1.0.2** (published 2020-07-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @ifreeworld/webpack-config
pnpm add @ifreeworld/webpack-config
yarn add @ifreeworld/webpack-config
bun add @ifreeworld/webpack-config
```

## 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.2 |
| Published | 2020-07-21 |
| First published | 2020-07-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 47 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| Author | wangzilong |
| Maintainers | wangzilong8 |

## Links

- npm: https://www.npmjs.com/package/@ifreeworld/webpack-config
- npm.io page: https://npm.io/package/@ifreeworld/webpack-config

## Dependencies (47)

- [less](https://npm.io/package/less.md) 3.9.0
- [svgo](https://npm.io/package/svgo.md) ^1.3.2
- [eslint](https://npm.io/package/eslint.md) ^4.19.1
- [webpack](https://npm.io/package/webpack.md) ^4.29.6
- [prettier](https://npm.io/package/prettier.md) ^2.0.5
- [css-loader](https://npm.io/package/css-loader.md) ^3.4.2
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [raw-loader](https://npm.io/package/raw-loader.md) ^1.0.0
- [url-loader](https://npm.io/package/url-loader.md) ^1.1.2
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.3.4
- [file-loader](https://npm.io/package/file-loader.md) ^3.0.1
- [html-loader](https://npm.io/package/html-loader.md) ^0.5.5
- [less-loader](https://npm.io/package/less-loader.md) ^4.1.0
- [svgo-loader](https://npm.io/package/svgo-loader.md) ^2.2.1
- [webpack-cli](https://npm.io/package/webpack-cli.md) ^3.2.3
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^10.1.0
- [babel-loader](https://npm.io/package/babel-loader.md) ^8.0.5
- [style-loader](https://npm.io/package/style-loader.md) ^1.1.3
- [thread-loader](https://npm.io/package/thread-loader.md) ^2.1.3
- [webpack-merge](https://npm.io/package/webpack-merge.md) ^4.2.2
- [postcss-loader](https://npm.io/package/postcss-loader.md) ^3.0.0
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.2.5
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.3.4
- [eslint-config-umi](https://npm.io/package/eslint-config-umi.md) ^0.1.1
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^3.2.1
- [@babel/preset-react](https://npm.io/package/@babel/preset-react.md) ^7.0.0
- [babel-plugin-import](https://npm.io/package/babel-plugin-import.md) ^1.8.0
- [babel-plugin-lodash](https://npm.io/package/babel-plugin-lodash.md) ^3.3.4
- [copy-webpack-plugin](https://npm.io/package/copy-webpack-plugin.md) ^5.0.0
- [eslint-plugin-react](https://npm.io/package/eslint-plugin-react.md) ^7.1.0
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^3.2.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.6.0
- [lodash-webpack-plugin](https://npm.io/package/lodash-webpack-plugin.md) ^0.11.5
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^6.11.0
- [eslint-plugin-flowtype](https://npm.io/package/eslint-plugin-flowtype.md) ^2.34.1
- [eslint-plugin-jsx-a11y](https://npm.io/package/eslint-plugin-jsx-a11y.md) ^5.1.1
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^3.1.3
- [webpack-tinypng-loader](https://npm.io/package/webpack-tinypng-loader.md) ^1.0.0
- [mini-css-extract-plugin](https://npm.io/package/mini-css-extract-plugin.md) ^0.5.0
- [webpack-bundle-analyzer](https://npm.io/package/webpack-bundle-analyzer.md) ^3.6.0
- [@babel/preset-typescript](https://npm.io/package/@babel/preset-typescript.md) ^7.8.3
- [speed-measure-webpack-plugin](https://npm.io/package/speed-measure-webpack-plugin.md) ^1.3.3
- [babel-plugin-transform-runtime](https://npm.io/package/babel-plugin-transform-runtime.md) ^6.23.0
- [@babel/plugin-proposal-decorators](https://npm.io/package/@babel/plugin-proposal-decorators.md) ^7.4.0
- [optimize-css-assets-webpack-plugin](https://npm.io/package/optimize-css-assets-webpack-plugin.md) ^5.0.1
- [@babel/plugin-proposal-class-properties](https://npm.io/package/@babel/plugin-proposal-class-properties.md) ^7.3.4
- [@babel/plugin-proposal-export-default-from](https://npm.io/package/@babel/plugin-proposal-export-default-from.md) ^7.2.0

## Recent versions

- 1.0.2 (latest) — 2020-07-21
- 1.0.1 — 2020-07-21
- 1.0.0 — 2020-07-21

## README

# 创建基础通用的 webpack 配置

## 安装

npm:

```shell
$ npm install @ifreeworld/webpack-config
```

## 使用

webpack.config.js
```javascript
const path = require('path');
const webpackConfig = require('@ifreeworld/webpack-config');

/**
 * 判断开发环境和生产环境作配置上的区分
 */
const isProduction = process.env.NODE_ENV === 'production';

/**
 * 基础 URL 路径
 */
const DEPLOY_PATH = process.env.DEPLOY_PATH || '';

const needAnalyzer = process.env.needAnalyzer === 'true';
const needSpeedMeasure = process.env.needSpeedMeasure === 'true';
const tinifyApiKey = process.env.tinifyApiKey || ''; // @sea https://tinypng.com/developers

module.exports = webpackConfig(__dirname, {
  isProduction,
  needAnalyzer,
  needSpeedMeasure,
  tinifyApiKey,
  publicPath: DEPLOY_PATH + '/',
  alias: {
    common: path.resolve(__dirname, './src/common'),
    components: path.resolve(__dirname, './src/components'),
    services: path.resolve(__dirname, 'src/services'),
    utils: path.resolve(__dirname, './src/utils'),
    icons: path.resolve(__dirname, './src/assets/icons'),
    file: path.resolve(__dirname, 'src/assets/files'),
    img: path.resolve(__dirname, './src/assets/img')
  },
  globalConstants: {
    // 基础 URL 路径
    'process.env.DEPLOY_PATH': '"' + DEPLOY_PATH + '"'
  },
  port: 8987,
  proxy: {
    '/api/': 'http://www.baidu.com/'
  },
  host: 'localhost'
});
```

src/index.js
```javascript
console.log('入口');
```

src/index.ejs
```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
  <title></title>
</head>
<body>
  <div id="root"></div>
</body>
</html>
```

| 参数 | 值类型 | 描述 |
| :-- | :-- | :-- |
| projectAbsolutePath | `string` | 当前项目的绝对路径 |
| options | `Object` | 选项 |
| isProduction | `boolean` | 是否是正式环境 |
| entry | `string` | 应用入口文件路径，默认为 `./src/index.js` |
| template | `string` | 应用 HTML 文件路径 |
| favicon | `string` | favicon 文件路径 |
| publicPath | `string` | 基础路径，默认为 `/` |
| alias | `Object` | 编译时的别名 |
| globalConstants | `Object` | 编译的全局常量 |
| port | `number` | devServer 端口号 |
| proxy | `Object` | devServer 代理配置 |
| extraTheme | `Object` | 自定义扩展 theme |
| needAnalyzer | `Boolean` | 是否需要生成代码分析报告 |
| needSpeedMeasure | `Boolean` | 是否开启打包速度分析工具 |

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