webpack.config.base.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. 'use strict'
  2. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  3. const { VueLoaderPlugin } = require('vue-loader')
  4. const ESLintPlugin = require('eslint-webpack-plugin');
  5. const ExtraneousFileCleanupPlugin = require('webpack-extraneous-file-cleanup-plugin');
  6. const CompressionPlugin = require("compression-webpack-plugin");
  7. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  8. const utils = require('./utils')
  9. const themePath = 'web/themes/custom/materiotheme'
  10. const langPath = 'web/sites/default/files/lang'
  11. const isDev = process.env.NODE_ENV === 'development';
  12. module.exports = {
  13. resolve: {
  14. extensions: ['.js', '.vue', '.json'],
  15. alias: {
  16. // 'vue': 'vue/dist/vue.js',
  17. 'vue' : isDev ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
  18. 'theme': utils.resolve(themePath),
  19. 'vuejs': utils.resolve(themePath+'/vuejs'),
  20. 'assets': utils.resolve(themePath+'/assets'),
  21. // locales are exported by strings_i18n_json_export from drupal
  22. 'locales': utils.resolve(langPath)
  23. }
  24. },
  25. entry: {
  26. 'main': utils.resolve(themePath + '/assets/scripts/main.js'),
  27. // 'lang-en': utils.resolve(langPath + '/en.json'),
  28. 'print': utils.resolve(themePath + '/assets/styles/print.scss')
  29. // 'mdi': utils.resolve(themePath + '/assets/styles/mdi/scss/materialdesignicons.scss')
  30. },
  31. output: {
  32. publicPath: '/themes/custom/materiotheme/assets/dist/',
  33. path: utils.resolve(themePath + '/assets/dist/'),
  34. filename: '[name].js',
  35. chunkFilename: '[name].bundle.js'
  36. },
  37. module: {
  38. rules: [
  39. // {
  40. // test: /\.(js|vue)$/,
  41. // loader: 'eslint-loader',
  42. // enforce: 'pre',
  43. // exclude: /node_modules/,
  44. // options: {
  45. // emitError: true,
  46. // emitWarning: true
  47. // }
  48. // },
  49. {
  50. test: /\.vue$/,
  51. use: 'vue-loader'
  52. },
  53. // {
  54. // resourceQuery: /blockType=i18n/,
  55. // type: 'javascript/auto',
  56. // loader: '@kazupon/vue-i18n-loader'
  57. // },
  58. // {
  59. // test: /\.js$/,
  60. // use: {
  61. // loader: 'babel-loader',
  62. // }
  63. // },
  64. {
  65. test: /\.(graphql|gql)$/,
  66. exclude: /node_modules/,
  67. loader: 'graphql-tag/loader'
  68. },
  69. {
  70. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  71. use: {
  72. loader: 'url-loader',
  73. options: {
  74. limit: 10000,
  75. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  76. }
  77. }
  78. }
  79. // {
  80. // test: /\.graphql?$/,
  81. // use: [
  82. // {
  83. // loader: 'webpack-graphql-loader',
  84. // options: {
  85. // // validate: true,
  86. // // schema: "./path/to/schema.json",
  87. // // removeUnusedFragments: true
  88. // // etc. See "Loader Options" below
  89. // }
  90. // }
  91. // ]
  92. // }
  93. // , {
  94. // test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  95. // use: {
  96. // loader: 'url-loader',
  97. // options: {
  98. // limit: 10000,
  99. // name: utils.assetsPath('img/[name].[hash:7].[ext]')
  100. // }
  101. // }
  102. // }, {
  103. // test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  104. // use: {
  105. // loader: 'url-loader',
  106. // options: {
  107. // limit: 10000,
  108. // name: utils.assetsPath('media/[name].[hash:7].[ext]')
  109. // }
  110. // }
  111. // }
  112. // {
  113. // test: /\.css$/,
  114. // use: [MiniCssExtractPlugin.loader, 'css-loader'],
  115. // },
  116. ]
  117. },
  118. optimization: {
  119. splitChunks: {
  120. cacheGroups: {
  121. // vsa: {
  122. // test: /[\\/]node_modules[\\/](vue-simple-accordion)[\\/]/,
  123. // name: 'vsa',
  124. // chunks: 'all',
  125. // usedExports: true
  126. // },
  127. vclb: {
  128. test: /[\\/]node_modules[\\/](vue-cool-lightbox)[\\/]/,
  129. name: 'vclb',
  130. chunks: 'all',
  131. usedExports: true
  132. },
  133. // vue_page_article: {
  134. // test: /[\\/]web[\\/]themes[\\/]custom[\\/]materiotheme[\\/]vuejs[\\/]components[\\/]Pages[\\/]Article.vue/,
  135. // name: 'vue_page_article',
  136. // chunks: 'all'
  137. // }
  138. },
  139. },
  140. },
  141. plugins: [
  142. new MiniCssExtractPlugin({
  143. filename: '[name].css'
  144. }),
  145. new VueLoaderPlugin(),
  146. new ESLintPlugin({
  147. // fix: true
  148. // exclude: ['web/.eslintrc.json']
  149. // cache: false,
  150. // ignore: true,
  151. // useEslintrc: false,
  152. }),
  153. new ExtraneousFileCleanupPlugin({
  154. extensions: ['.js'],
  155. paths: [utils.resolve(themePath + '/assets/dist/')],
  156. minBytes: 4096
  157. }),
  158. new CompressionPlugin(),
  159. /**
  160. * All files inside webpack's output.path directory will be removed once, but the
  161. * directory itself will not be. If using webpack 4+'s default configuration,
  162. * everything under <PROJECT_DIR>/dist/ will be removed.
  163. * Use cleanOnceBeforeBuildPatterns to override this behavior.
  164. *
  165. * During rebuilds, all webpack assets that are not used anymore
  166. * will be removed automatically.
  167. *
  168. * See `Options and Defaults` for information
  169. */
  170. new CleanWebpackPlugin(),
  171. ]
  172. }