easywebpack 获取原生 Webpack 配置

easywebpack.getWebpackConfig(config)

这种获取方式是指通过解决方案获取配置, 参数 config 支持如下三种配置:
config 为 null 或 undefined 时, 目前读取项目根目录下的 webpack.config.js
config 为 object 时, 也就是直接传入 webpack.config.js 的配置
config 为 string 时, 表示指定 webpack.config.js 自定义配置文件路径

获取 Webpack 配置

const easy = require('easywebpack');
const webpackConfig = easy.getWebpackConfig({
  env: process.env.BUILD_ENV,  // 支持dev, test, prod 模式
  target: 'web',
  entry: {
    app: 'src/lib.js'
  }
});

获取 Vue 项目配置

默认 Node 和 Web 构建的 Webpack 配置,总共两个配置, 通过 target: web 获取前端配置

const easy = require('easywebpack-vue');
const webpackConfig = easy.getWebpackConfig({
  env: process.env.BUILD_ENV,  // 支持dev, test, prod 模式
  target: 'web',
  entry: {
    app: 'src/lib.js'
  }
});

获取 React 项目配置

默认 Node 和 Web 构建的 Webpack 配置,总共两个配置, 通过 target: web 获取前端配置

const easy = require('easywebpack-react');
const webpackConfig = easy.getWebpackConfig({
  env: process.env.BUILD_ENV,  // 支持dev, test, prod 模式
  target: 'web',
  entry: {
    app: 'src/lib.js'
  }
});

获取 HTML 项目配置

const easy = require('easywebpack-html');
const webpackConfig = easy.getWebpackConfig({
  env: process.env.BUILD_ENV,  // 支持dev, test, prod 模式
  template: 'src/template.html'
  entry: {
    app: 'src/lib.js'
  }
});

获取 JS 打包配置

const easy = require('easywebpack-js');
const webpackConfig = easy.getWebpackConfig({
  env: process.env.BUILD_ENV,  // 支持dev, test, prod 模式
  entry: {
    app: 'src/lib.js'
  }
});

Weex 解决方案

  • 内置方法
const EasyWebpack = require('easywebpack-weex');
const webpackConfig = EasyWebpack.getWebpackConfig();
  • builder方式
const EasyWebpack = require('easywebpack-weex');
// Weex Native App Webpack编译配置
const webpackConfig = new EasyWebpack.WebpackWeexBuilder(config).create();
// Weex Web Webpack编译配置
const webpackConfig = new EasyWebpack.WebpackWebBuilder(config).create();

Author: sky
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source sky !
 Previous
optimizaiton optimizaiton
从 webpack 4 开始,会根据你选择的 mode 来执行不同的优化,你可以通过 optimizaiton 节点进行覆盖配置。在 easywebpack 体系中,会进行进步配置简化。easywebpack 默认配置请根据需要,覆盖默认配置, 默认配置逻辑具体见:https://gith...
2020-04-18 sky
Next 
PostCss PostCss
默认配置postcss.config.js
2020-04-18 sky