webpack.config.base.js 3.4 KB

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