webpack.conf.js 1.6 KB

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