webpack.config.base.js 4.4 KB

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