webpack.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const path = require('path');
  2. const glob = require('glob');
  3. // Minify JS
  4. const MinifyPlugin = require('babel-minify-webpack-plugin');
  5. // This plugin extracts the CSS into its own file instead of tying it with the JS.
  6. // It prevents:
  7. // - not having styles due to a JS error
  8. // - the flash page without styles during JS loading
  9. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  10. const extractCssDefault = new ExtractTextPlugin({
  11. filename: "../css/[name].min.css",
  12. publicPath: 'tpl/default/css/',
  13. });
  14. const extractCssVintage = new ExtractTextPlugin({
  15. filename: "../css/[name].min.css",
  16. publicPath: 'tpl/vintage/css/',
  17. });
  18. module.exports = [
  19. {
  20. entry: {
  21. picwall: './assets/common/js/picwall.js',
  22. pluginsadmin: './assets/default/js/plugins-admin.js',
  23. shaarli: [
  24. './assets/default/js/base.js',
  25. './assets/default/scss/shaarli.scss',
  26. ].concat(glob.sync('./assets/default/img/*')),
  27. },
  28. output: {
  29. filename: '[name].min.js',
  30. path: path.resolve(__dirname, 'tpl/default/js/')
  31. },
  32. module: {
  33. rules: [
  34. {
  35. test: /\.js$/,
  36. exclude: /node_modules/,
  37. use: {
  38. loader: 'babel-loader',
  39. options: {
  40. presets: [
  41. 'babel-preset-env',
  42. ]
  43. }
  44. }
  45. },
  46. {
  47. test: /\.scss/,
  48. use: extractCssDefault.extract({
  49. use: [{
  50. loader: "css-loader",
  51. options: {
  52. minimize: true,
  53. }
  54. }, {
  55. loader: "sass-loader"
  56. }],
  57. })
  58. },
  59. {
  60. test: /\.(gif|png|jpe?g|svg|ico)$/i,
  61. use: [
  62. {
  63. loader: 'file-loader',
  64. options: {
  65. name: '../img/[name].[ext]',
  66. publicPath: 'tpl/default/img/',
  67. }
  68. }
  69. ],
  70. },
  71. {
  72. test: /\.(eot|ttf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  73. loader: 'file-loader',
  74. options: {
  75. name: '../fonts/[name].[ext]',
  76. // do not add a publicPath here because it's already handled by CSS's publicPath
  77. publicPath: '',
  78. }
  79. },
  80. ],
  81. },
  82. plugins: [
  83. new MinifyPlugin(),
  84. extractCssDefault,
  85. ],
  86. },
  87. {
  88. entry: {
  89. shaarli: [
  90. './assets/vintage/js/base.js',
  91. './assets/vintage/css/reset.css',
  92. './assets/vintage/css/shaarli.css',
  93. ].concat(glob.sync('./assets/vintage/img/*')),
  94. picwall: './assets/common/js/picwall.js',
  95. },
  96. output: {
  97. filename: '[name].min.js',
  98. path: path.resolve(__dirname, 'tpl/vintage/js/')
  99. },
  100. module: {
  101. rules: [
  102. {
  103. test: /\.js$/,
  104. exclude: /node_modules/,
  105. use: {
  106. loader: 'babel-loader',
  107. options: {
  108. presets: [
  109. 'babel-preset-env',
  110. ]
  111. }
  112. }
  113. },
  114. {
  115. test: /\.css$/,
  116. use: extractCssVintage.extract({
  117. use: [{
  118. loader: "css-loader",
  119. options: {
  120. minimize: true,
  121. }
  122. }],
  123. })
  124. },
  125. {
  126. test: /\.(gif|png|jpe?g|svg|ico)$/i,
  127. use: [
  128. {
  129. loader: 'file-loader',
  130. options: {
  131. name: '../img/[name].[ext]',
  132. publicPath: '',
  133. }
  134. }
  135. ],
  136. },
  137. ],
  138. },
  139. plugins: [
  140. new MinifyPlugin(),
  141. extractCssVintage,
  142. ],
  143. },
  144. ];