webpack.config.base.js 4.3 KB

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