1.1.11 • Published 3 years ago

eefe-webpack-config v1.1.11

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

介绍

创建基础通用的 webpack 配置

安装

$ npm install eefe-webpack-config --save-dev

使用

  • 公共配置(webpack-common-config.js 文件)
const path = require('path');
const createWebpackConfig = require('eefe-webpack-config');

module.exports = (options) => {
  // 创建配置
  const config = createWebpackConfig(__dirname, {
    alias: {
      '@': path.join(__dirname, '../src'),
      api: path.join(__dirname, '../src/api'),
    },
    ...options,
  });
  return config;
};
  • development 环境配置(webpack-dev-config.js 文件)
const config = require('./webpack.common');

module.exports = config({
  proxy: {
    '/api': {
      target: 'https://api.github.com',
      changeOrigin: true,
      pathRewrite: { '^/api': '' },
    },
  },
});
  • production 环境配置(webpack-prod-config.js 文件)
const config = require('./webpack.common');

module.exports = config({
  isProduction: true, // 生产环境必须传
});
参数值类型描述
projectAbsolutePathstring当前项目的绝对路径
optionsobject选项
customConfigobject自定义配置

options 对象下的参数 | 参数 | 值类型 | 描述 | | :----------- | :-------- | :--------------------------------------------------------------------- | | isProduction | boolean | 是否是正式环境 | | entry | string | 应用入口文件路径,默认为 ./src/main.js | | template | string | 应用 HTML 文件路径 | | alias | object | 编译时的别名 | | port | number | devServer 端口号 | | proxy | object | devServer 代理配置 | | host | string | devServer 服务器监听的地址 | | customConfig | object | 自定义配置(若是针对某个环境的配置需在传入时判断环境,否则为公共配置) |

guojiamin,2021.08.19