webpack.conf.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const path = require('path');
  2. const TerserPlugin = require('terser-webpack-plugin');
  3. module.exports = (env, argv) => ({
  4. entry: {
  5. admin: './app/main.js'
  6. },
  7. devtool: argv.mode === 'production' ? false : 'eval-source-map',
  8. target: 'web',
  9. output: {
  10. path: path.resolve(__dirname, 'js'),
  11. filename: '[name].min.js',
  12. chunkFilename: 'vendor.min,js',
  13. library: 'Grav'
  14. },
  15. optimization: {
  16. minimize: argv.mode === 'disabled-production',
  17. minimizer: [new TerserPlugin()],
  18. splitChunks: {
  19. cacheGroups: {
  20. vendors: {
  21. test: /[\\/]node_modules[\\/]/,
  22. priority: 1,
  23. name: 'vendor',
  24. enforce: true,
  25. chunks: 'all'
  26. }
  27. }
  28. }
  29. },
  30. externals: {
  31. jquery: 'jQuery',
  32. 'grav-config': 'GravAdmin'
  33. },
  34. module: {
  35. rules: [
  36. { enforce: 'pre', test: /\.json$/, loader: 'json-loader' },
  37. { enforce: 'pre', test: /\.js$/, loader: 'eslint-loader', exclude: /node_modules/ },
  38. {
  39. test: /\.css$/,
  40. use: ['style-loader', 'css-loader']
  41. },
  42. {
  43. test: /\.js$/,
  44. loader: 'babel-loader',
  45. exclude: /node_modules/,
  46. options: {
  47. presets: ['@babel/preset-env'],
  48. plugins: ['@babel/plugin-proposal-object-rest-spread']
  49. }
  50. }
  51. ]
  52. }
  53. });