webpack.common.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* eslint-disable */
  2. // Common Config is used in Development and Production Mode.
  3. const path = require('path');
  4. const CleanWebpackPlugin = require('clean-webpack-plugin');
  5. const webpack = require('webpack');
  6. const HtmlWebPackPlugin = require('html-webpack-plugin');
  7. const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
  8. const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
  9. const StylelintPlugin = require('stylelint-webpack-plugin');
  10. const ESLintPlugin = require('eslint-webpack-plugin');
  11. const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
  12. // Linting
  13. const TSLintPlugin = require('tslint-webpack-plugin');
  14. const ImageminPlugin = require('imagemin-webpack-plugin').default;
  15. const imageminMozjpeg = require('imagemin-mozjpeg');
  16. module.exports = {
  17. entry: {
  18. index: './src/index.ts'
  19. },
  20. output: {
  21. path: path.resolve(__dirname, 'dist'),
  22. filename: './js/[name].[hash:6].bundle.js'
  23. },
  24. module: {
  25. rules: [
  26. // Raw Loader
  27. {
  28. test: /\.txt$/,
  29. use: 'raw-loader'
  30. },
  31. // HTML Loader
  32. {
  33. test: /\.html$/,
  34. use: [
  35. {
  36. loader: 'html-loader',
  37. options: {minimize: true}
  38. }
  39. ]
  40. },
  41. // CSS/SCSS Loader & Minimizer
  42. {
  43. test: /\.(sa|sc|c)ss$/,
  44. use: [
  45. "style-loader",
  46. "css-loader",
  47. {
  48. loader: 'postcss-loader',
  49. options: {
  50. postcssOptions: {
  51. parser: "sugarss",
  52. },
  53. },
  54. },
  55. {
  56. loader: 'resolve-url-loader',
  57. options: {}
  58. },
  59. {
  60. loader: 'sass-loader',
  61. options: {
  62. sourceMap: true,
  63. sourceMapContents: false
  64. }
  65. }
  66. ],
  67. },
  68. {
  69. test: /\.svg$/,
  70. use: [
  71. {
  72. loader: 'svg-sprite-loader',
  73. options: {
  74. extract: true,
  75. } },
  76. 'svg-transform-loader',
  77. {
  78. loader: 'svgo-loader',
  79. options: {
  80. plugins: [
  81. {removeTitle: true},
  82. {convertColors: {shorthex: false}},
  83. {convertPathData: false},
  84. {convertPathData:true}
  85. ]
  86. }
  87. }
  88. ]
  89. },
  90. // Image Loader
  91. {
  92. test: /\.(png|jpeg|jpg|webp|gif|ico)/i,
  93. use: [
  94. {
  95. loader: 'url-loader',
  96. options: {
  97. // publicPath: '../',
  98. //name: './assets/images/' + '[name].[ext]',
  99. limit: 10000,
  100. //limit:false,
  101. //publicPath: '../'
  102. }
  103. },
  104. ]
  105. },
  106. // Babel Loader
  107. {
  108. test: /\.ts(x?)$/,
  109. exclude: /node_modules/,
  110. loader: 'babel-loader'
  111. },
  112. {
  113. test: /\.m?js$/,
  114. exclude: /(node_modules|bower_components)/,
  115. use: {
  116. loader: 'babel-loader',
  117. options: {
  118. presets: ['@babel/preset-env'],
  119. plugins: [
  120. '@babel/plugin-proposal-object-rest-spread',
  121. '@babel/plugin-proposal-nullish-coalescing-operator',
  122. '@babel/plugin-proposal-optional-chaining',
  123. '@babel/plugin-proposal-class-properties'
  124. ]
  125. }
  126. },
  127. },
  128. // XML Loader
  129. {
  130. test: /\.xml$/,
  131. use: [
  132. 'xml-loader'
  133. ]
  134. },
  135. {
  136. test: require.resolve("bootstrap"),
  137. loader: "expose-loader",
  138. options: {
  139. exposes: ["bootstrap"],
  140. },
  141. },
  142. {
  143. test: require.resolve("jquery"),
  144. loader: "expose-loader",
  145. options: {
  146. exposes: ["$", "jQuery"],
  147. },
  148. },
  149. {
  150. test: require.resolve("underscore"),
  151. loader: "expose-loader",
  152. options: {
  153. exposes: [
  154. "_.map|map",
  155. {
  156. globalName: "_.reduce",
  157. moduleLocalName: "reduce",
  158. },
  159. {
  160. globalName: ["_", "filter"],
  161. moduleLocalName: "filter",
  162. },
  163. ],
  164. },
  165. },
  166. ]
  167. },
  168. resolve: {
  169. extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'],
  170. alias: {
  171. riSvg: 'remixicon/icons/'
  172. }
  173. },
  174. plugins: [
  175. new CleanWebpackPlugin(),
  176. new ImageminPlugin({
  177. test: /\.(jpe?g|png|gif|svg)$/i,
  178. // lossLess gif compressor
  179. gifsicle: {
  180. optimizationLevel: 9
  181. },
  182. // lossy png compressor, remove for default lossLess
  183. pngquant: ({
  184. quality: '75'
  185. }),
  186. // lossy jpg compressor
  187. plugins: [imageminMozjpeg({
  188. quality: '75'
  189. })],
  190. destination: './webpack',
  191. }),
  192. new ESLintPlugin({
  193. cache: true,
  194. ignore: true,
  195. useEslintrc: true,
  196. }),
  197. new HtmlWebPackPlugin({
  198. title: 'SqueezeESP32',
  199. template: './src/index.ejs',
  200. filename: 'index.html',
  201. inject: 'body',
  202. minify: {
  203. html5 : true,
  204. collapseWhitespace : true,
  205. minifyCSS : true,
  206. minifyJS : true,
  207. minifyURLs : false,
  208. removeAttributeQuotes : true,
  209. removeComments : true, // false for Vue SSR to find app placeholder
  210. removeEmptyAttributes : true,
  211. removeOptionalTags : true,
  212. removeRedundantAttributes : true,
  213. removeScriptTypeAttributes : true,
  214. removeStyleLinkTypeAttributese : true,
  215. useShortDoctype : true
  216. },
  217. favicon: "./src/assets/images/favicon-32x32.png",
  218. excludeChunks: ['test'],
  219. }),
  220. new ScriptExtHtmlWebpackPlugin({
  221. defaultAttribute: 'defer'
  222. }),
  223. // // Load Lodash Features Separately https://www.npmjs.com/package/lodash-webpack-plugin
  224. new LodashModuleReplacementPlugin({
  225. 'collections': true,
  226. 'paths': true,
  227. }),
  228. new TSLintPlugin({
  229. files: ['./src/ts/*.ts']
  230. }),
  231. new StylelintPlugin( {
  232. files: ['./src/sass/*.s?(a|c)ss'],
  233. configFile: './config/.stylelintrc',
  234. emitError: true,
  235. emitWarning: true,
  236. failOnError: false,
  237. fix: true
  238. }),
  239. new SpriteLoaderPlugin({plainSprite: true})
  240. ],
  241. };