build.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
  2. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  3. const TerserPlugin = require('terser-webpack-plugin');
  4. const {version} = require('../package');
  5. const bundles = require('./bundles');
  6. const util = require('util');
  7. const webpack = util.promisify(require('webpack'));
  8. const path = require('path');
  9. (async () => {
  10. const banner = new webpack.BannerPlugin(`Pickr ${version} MIT | https://github.com/Simonwep/pickr`);
  11. // CSS
  12. await webpack({
  13. mode: 'production',
  14. entry: {
  15. 'classic': path.resolve('./src/scss/themes/classic.scss'),
  16. 'monolith': path.resolve('./src/scss/themes/monolith.scss'),
  17. 'nano': path.resolve('./src/scss/themes/nano.scss')
  18. },
  19. output: {
  20. path: path.resolve('./dist/themes')
  21. },
  22. module: {
  23. rules: [
  24. {
  25. test: /\.scss$/,
  26. use: [
  27. MiniCssExtractPlugin.loader,
  28. 'css-loader',
  29. {
  30. loader: 'postcss-loader',
  31. options: {
  32. postcssOptions: {
  33. plugins: [
  34. require('autoprefixer')
  35. ]
  36. }
  37. },
  38. },
  39. 'sass-loader'
  40. ]
  41. }
  42. ]
  43. },
  44. plugins: [
  45. banner,
  46. new FixStyleOnlyEntriesPlugin(),
  47. new MiniCssExtractPlugin({
  48. filename: '[name].min.css'
  49. })
  50. ]
  51. });
  52. // Chaining promises to prevent issues caused by both filename configurations
  53. // writing a minified CSS file; both processes having handles on the files can
  54. // result in strange suffixes that fail to parse due to an extra `ap*/`
  55. for (const {filename, babelConfig} of bundles) {
  56. console.log(`Create ${filename}`);
  57. await webpack({
  58. mode: 'production',
  59. entry: path.resolve('./src/js/pickr.js'),
  60. output: {
  61. filename,
  62. path: path.resolve('./dist'),
  63. library: 'Pickr',
  64. libraryExport: 'default',
  65. libraryTarget: 'umd'
  66. },
  67. module: {
  68. rules: [
  69. {
  70. test: /\.m?js$/,
  71. exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
  72. include: [
  73. path.join(__dirname, '..', 'node_modules/nanopop'),
  74. path.join(__dirname, '..', 'src')
  75. ],
  76. use: [
  77. {
  78. loader: 'babel-loader',
  79. options: babelConfig
  80. }
  81. ]
  82. }
  83. ]
  84. },
  85. plugins: [
  86. banner,
  87. new webpack.SourceMapDevToolPlugin({
  88. filename: `${filename}.map`
  89. }),
  90. new webpack.DefinePlugin({
  91. VERSION: JSON.stringify(version)
  92. })
  93. ],
  94. optimization: {
  95. minimizer: [
  96. new TerserPlugin({
  97. extractComments: false
  98. })
  99. ]
  100. }
  101. });
  102. }
  103. console.log('Done');
  104. })();