ironhee/webpack-umd-external

语言: JavaScript

git: https://github.com/ironhee/webpack-umd-external

为umd库创建webpack外部对象
make webpack external object for umd library
README.md (中文)

安装

npm install -D webpack-umd-external

用法

之前

module.exports = {
  entry: {
    'myModule': './src/my_module.js'
  },
  output: {
    path: './dist/',
    filename: 'my_module.js',
    library: 'MyModule',
    libraryTarget: 'umd'
  },
  externals: {
    'jquery': {
      root: '$',
      commonjs2: 'jquery',
      commonjs: 'jquery',
      amd: 'jquery'
    },
    'lodash': {
      root: '_',
      commonjs2: 'lodash',
      commonjs: 'lodash',
      amd: 'lodash'
    },
    'q': {
      root: 'Q',
      commonjs2: 'q',
      commonjs: 'q',
      amd: 'q'
    }
  }
};

var webpackUMDExternal = require('webpack-umd-external');

module.exports = {
  entry: {
    'myModule': './src/my_module.js'
  },
  output: {
    path: './dist/',
    filename: 'my_module.js',
    library: 'MyModule',
    libraryTarget: 'umd'
  },
  externals: webpackUMDExternal({
    'jquery': '$',
    'lodash': '_',
    'q': 'Q'
  })
};

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

Install

npm install -D webpack-umd-external

Usage

before

module.exports = {
  entry: {
    'myModule': './src/my_module.js'
  },
  output: {
    path: './dist/',
    filename: 'my_module.js',
    library: 'MyModule',
    libraryTarget: 'umd'
  },
  externals: {
    'jquery': {
      root: '$',
      commonjs2: 'jquery',
      commonjs: 'jquery',
      amd: 'jquery'
    },
    'lodash': {
      root: '_',
      commonjs2: 'lodash',
      commonjs: 'lodash',
      amd: 'lodash'
    },
    'q': {
      root: 'Q',
      commonjs2: 'q',
      commonjs: 'q',
      amd: 'q'
    }
  }
};

after

var webpackUMDExternal = require('webpack-umd-external');

module.exports = {
  entry: {
    'myModule': './src/my_module.js'
  },
  output: {
    path: './dist/',
    filename: 'my_module.js',
    library: 'MyModule',
    libraryTarget: 'umd'
  },
  externals: webpackUMDExternal({
    'jquery': '$',
    'lodash': '_',
    'q': 'Q'
  })
};