webpack.config.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* global __dirname, require, module*/
  2. const path = require('path');
  3. const env = require('yargs').argv.env; // use --env with webpack 2
  4. const pkg = require('./package.json');
  5. let libraryName = pkg.name;
  6. let outputFile, mode;
  7. if (env === 'build') {
  8. mode = 'production';
  9. outputFile = libraryName + '.min.js';
  10. } else {
  11. mode = 'development';
  12. outputFile = libraryName + '.js';
  13. }
  14. const config = {
  15. mode: mode,
  16. entry: __dirname + '/src/index.js',
  17. devtool: mode === 'production' ? false : 'inline-source-map',
  18. output: {
  19. path: __dirname + '/lib',
  20. filename: outputFile,
  21. library: libraryName,
  22. libraryTarget: 'umd',
  23. umdNamedDefine: true,
  24. globalObject: "typeof self !== 'undefined' ? self : this"
  25. },
  26. module: {
  27. rules: [
  28. {
  29. test: /(\.js)$/,
  30. loader: 'babel-loader',
  31. exclude: /(node_modules)/
  32. },
  33. {
  34. test: /(\.js)$/,
  35. loader: 'eslint-loader',
  36. exclude: /node_modules/,
  37. options: {
  38. fix: true
  39. }
  40. }
  41. ]
  42. },
  43. resolve: {
  44. modules: [path.resolve('./node_modules'), path.resolve('./src')],
  45. extensions: ['.json', '.js']
  46. }
  47. };
  48. module.exports = config;