webpack.config.base.js 5.8 KB

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