webpack.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const pkg = require('../package.json');
  5. const bannerPack = new webpack.BannerPlugin({
  6. banner: [
  7. `Quill Editor v${pkg.version}`,
  8. 'https://quilljs.com/',
  9. 'Copyright (c) 2014, Jason Chen',
  10. 'Copyright (c) 2013, salesforce.com',
  11. ].join('\n'),
  12. entryOnly: true,
  13. });
  14. const constantPack = new webpack.DefinePlugin({
  15. QUILL_VERSION: JSON.stringify(pkg.version),
  16. });
  17. const source = [
  18. 'quill.ts',
  19. 'core.ts',
  20. 'blots',
  21. 'core',
  22. 'formats',
  23. 'modules',
  24. 'test',
  25. 'themes',
  26. 'ui',
  27. ].map(file => {
  28. return path.resolve(__dirname, '..', file);
  29. });
  30. const jsRules = {
  31. test: /\.(j|t)s$/,
  32. include: source,
  33. use: ['babel-loader'],
  34. };
  35. const svgRules = {
  36. test: /\.svg$/,
  37. include: [path.resolve(__dirname, '../assets/icons')],
  38. use: [
  39. {
  40. loader: 'html-loader',
  41. options: {
  42. minimize: true,
  43. },
  44. },
  45. ],
  46. };
  47. const stylRules = {
  48. test: /\.styl$/,
  49. include: [path.resolve(__dirname, '../assets')],
  50. use: [MiniCssExtractPlugin.loader, 'css-loader', 'stylus-loader'],
  51. };
  52. const baseConfig = {
  53. mode: 'development',
  54. context: path.resolve(__dirname, '..'),
  55. entry: {
  56. 'quill.js': ['./quill.ts'],
  57. 'quill.core.js': ['./core.ts'],
  58. 'quill.core': './assets/core.styl',
  59. 'quill.bubble': './assets/bubble.styl',
  60. 'quill.snow': './assets/snow.styl',
  61. },
  62. output: {
  63. filename: '[name]',
  64. library: 'Quill',
  65. libraryExport: 'default',
  66. libraryTarget: 'umd',
  67. path: path.resolve(__dirname, '../dist/'),
  68. clean: true,
  69. },
  70. resolve: {
  71. extensions: ['.js', '.styl', '.ts'],
  72. },
  73. module: {
  74. rules: [jsRules, stylRules, svgRules],
  75. noParse: [
  76. /\/node_modules\/clone\/clone\.js$/,
  77. /\/node_modules\/eventemitter3\/index\.js$/,
  78. /\/node_modules\/extend\/index\.js$/,
  79. ],
  80. },
  81. plugins: [
  82. bannerPack,
  83. constantPack,
  84. new MiniCssExtractPlugin({
  85. filename: '[name].css',
  86. }),
  87. ],
  88. devServer: {
  89. static: {
  90. directory: path.resolve(__dirname, '../dist'),
  91. },
  92. hot: false,
  93. port: process.env.npm_package_config_ports_webpack,
  94. allowedHosts: 'all',
  95. devMiddleware: {
  96. stats: 'minimal',
  97. },
  98. },
  99. };
  100. module.exports = env => {
  101. if (env?.minimize) {
  102. const { devServer, ...prodConfig } = baseConfig;
  103. return {
  104. ...prodConfig,
  105. mode: 'production',
  106. entry: { 'quill.min.js': './quill.ts' },
  107. devtool: 'source-map',
  108. };
  109. }
  110. if (env?.coverage) {
  111. baseConfig.module.rules[0].use[0].options.plugins = ['istanbul'];
  112. return baseConfig;
  113. }
  114. return baseConfig;
  115. };