webpack.config.base.js 3.9 KB

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