webpack.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  2. const TerserJSPlugin = require('terser-webpack-plugin');
  3. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  4. const devMode = process.env.NODE_ENV !== 'production';
  5. module.exports = {
  6. entry: {
  7. 'zuck.js': './src/zuck.js',
  8. zuck: './src/zuck.css'
  9. },
  10. module: {
  11. rules: [
  12. {
  13. test: /\.(js)$/,
  14. exclude: /node_modules/,
  15. use: ['babel-loader']
  16. },
  17. {
  18. test: /\.css$/,
  19. use: [MiniCssExtractPlugin.loader, 'css-loader']
  20. }
  21. ]
  22. },
  23. resolve: {
  24. extensions: ['*', '.js', 'css']
  25. },
  26. plugins: [
  27. new MiniCssExtractPlugin({
  28. filename: devMode ? '[name].css' : '[name].min.css'
  29. })
  30. ],
  31. output: {
  32. path: `${__dirname}/dist`,
  33. publicPath: '/',
  34. filename: (chunkData) => {
  35. let [name, extension] = chunkData.chunk.name.split('.');
  36. let suffix = devMode ? '' : '.min';
  37. if (extension) {
  38. extension = `.${extension}`;
  39. } else {
  40. suffix = '';
  41. extension = devMode ? '.css.js' : '.css.min.js';
  42. }
  43. return `${name}${suffix}${extension}`;
  44. },
  45. library: 'Zuck'
  46. },
  47. optimization: {
  48. minimize: !devMode,
  49. minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})]
  50. },
  51. devServer: {
  52. contentBase: __dirname,
  53. host: '127.0.0.1',
  54. port: 8080
  55. }
  56. };