1webpack.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // webpack.config.js
  2. /* eslint-disable */
  3. const path = require('path')
  4. const webpack = require('webpack')
  5. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  6. const ENVIRONMENT = process.env.NODE_ENV
  7. const PRODUCTION = ENVIRONMENT === 'production'
  8. const SOURCEMAP = !PRODUCTION || process.env.SOURCEMAP
  9. const library = 'modularity-front' // << RENAME THIS <<
  10. const filename = PRODUCTION ? `${library}.min.js` : `${library}.js`
  11. const plugins = []
  12. if (PRODUCTION) {
  13. plugins.push(
  14. new webpack.DefinePlugin({
  15. 'process.env.NODE_ENV': JSON.stringify(ENVIRONMENT),
  16. }),
  17. new webpack.optimize.ModuleConcatenationPlugin()
  18. )
  19. }
  20. module.exports = {
  21. devtool: SOURCEMAP ? 'source-map' : 'none',
  22. entry: `${__dirname}/src/exports.js`, // << RENAME THIS <<
  23. externals: {
  24. 'react': 'react',
  25. 'react-dom': 'react-dom',
  26. },
  27. mode: PRODUCTION ? "production" : "development",
  28. module: {
  29. rules: [{
  30. test: /\.js$/,
  31. loader: 'babel-loader',
  32. exclude: /node_modules/,
  33. }],
  34. },
  35. output: {
  36. filename,
  37. library,
  38. path: `${__dirname}/lib`,
  39. libraryTarget: 'umd',
  40. umdNamedDefine: true,
  41. },
  42. optimization: {
  43. minimizer: [
  44. // we specify a custom UglifyJsPlugin here to get source maps in production
  45. new UglifyJsPlugin({
  46. cache: true,
  47. parallel: true,
  48. uglifyOptions: {
  49. compress: false,
  50. ecma: 6,
  51. mangle: true
  52. },
  53. sourceMap: true
  54. })
  55. ]
  56. },
  57. plugins
  58. }