webpack.config.base.js 5.7 KB

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