webpack.config.base.js 4.5 KB

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