easywebpack 获取原生 Webpack 配置

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

获取 Webpack 配置

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

获取 Vue 项目配置

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

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

获取 React 项目配置

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

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

获取 HTML 项目配置

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

获取 JS 打包配置

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

Weex 解决方案

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