webpack.conf.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var webpack = require('webpack');
  2. var path = require('path');
  3. var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  4. var isProd = process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'production-wip';
  5. module.exports = {
  6. entry: {
  7. site: './app/main.js'
  8. },
  9. devtool: isProd ? false : 'eval-source-map',
  10. target: 'web',
  11. output: {
  12. path: path.resolve(__dirname, 'assets'),
  13. filename: 'form.min.js',
  14. chunkFilename: 'form.vendor.js'
  15. },
  16. optimization: {
  17. minimize: isProd,
  18. minimizer: [
  19. new UglifyJsPlugin({
  20. uglifyOptions: {
  21. compress: {
  22. drop_console: true
  23. },
  24. dead_code: true
  25. }
  26. })
  27. ],
  28. splitChunks: {
  29. cacheGroups: {
  30. vendors: {
  31. test: /[\\/]node_modules[\\/]/,
  32. priority: 1,
  33. name: 'vendor',
  34. enforce: true,
  35. chunks: 'all'
  36. }
  37. }
  38. }
  39. },
  40. plugins: [
  41. new webpack.ProvidePlugin({
  42. 'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch'
  43. })
  44. ],
  45. externals: {
  46. jquery: 'jQuery',
  47. 'grav-form': 'GravForm'
  48. },
  49. module: {
  50. rules: [
  51. { enforce: 'pre', test: /\.json$/, loader: 'json-loader' },
  52. { enforce: 'pre', test: /\.js$/, loader: 'eslint-loader', exclude: /node_modules/ },
  53. { test: /\.css$/, loader: 'style-loader!css-loader' },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader',
  57. exclude: /node_modules/,
  58. query: {
  59. presets: ['@babel/preset-env']
  60. }
  61. }
  62. ]
  63. }
  64. };