webpack.config.base.js 4.5 KB

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