webpack.config.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. var TerserPlugin = require('terser-webpack-plugin');
  4. module.exports = {
  5. entry: ['./node_modules/regenerator-runtime/runtime.js', './lofig.js'],
  6. output: {
  7. path: path.resolve(__dirname, './dist'),
  8. publicPath: '/dist',
  9. filename: 'lofig.min.js',
  10. },
  11. resolve: {
  12. alias: {
  13. modules: path.join(__dirname, 'node_modules')
  14. }
  15. },
  16. module: {
  17. rules: [
  18. {
  19. test: /\.js$/,
  20. exclude: /node_modules/,
  21. use: {
  22. loader: 'babel-loader',
  23. options: {
  24. presets: ['@babel/preset-env']
  25. }
  26. }
  27. }
  28. ]
  29. },
  30. devServer: {
  31. historyApiFallback: true,
  32. noInfo: true,
  33. contentBase: './example'
  34. },
  35. devtool: 'source-map',
  36. optimization: {
  37. minimize: true,
  38. minimizer: [new TerserPlugin()],
  39. usedExports: true,
  40. },
  41. }
  42. if (process.env.NODE_ENV === 'production') {
  43. module.exports.devtool = 'inline-source-map'
  44. module.exports.plugins = (module.exports.plugins || []).concat([
  45. new webpack.DefinePlugin({
  46. 'process.env': {
  47. NODE_ENV: '"production"'
  48. }
  49. }),
  50. new webpack.optimize.OccurenceOrderPlugin()
  51. ])
  52. }