2
0

webpack.common.js 7.3 KB

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