Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

webpack.common.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* eslint-disable camelcase */
  2. const { VueLoaderPlugin } = require('vue-loader')
  3. const path = require('path')
  4. const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
  5. const ESLintPlugin = require('eslint-webpack-plugin')
  6. const webpack = require('webpack')
  7. const modules = require('./webpack.modules.js')
  8. const formatOutputFromModules = (modules) => {
  9. // merge all configs into one object, and use AppID to generate the fileNames
  10. // with the following format:
  11. // AppId-fileName: path/to/js-file.js
  12. const moduleEntries = Object.keys(modules).map(moduleKey => {
  13. const module = modules[moduleKey]
  14. const entries = Object.keys(module).map(entryKey => {
  15. const entry = module[entryKey]
  16. return { [`${moduleKey}-${entryKey}`]: entry }
  17. })
  18. return Object.assign({}, ...Object.values(entries))
  19. })
  20. return Object.assign({}, ...Object.values(moduleEntries))
  21. }
  22. const modulesToBuild = () => {
  23. const MODULE = process.env.MODULE
  24. if (MODULE) {
  25. if (!modules[MODULE]) {
  26. throw new Error(`No module "${MODULE}" found`)
  27. }
  28. return formatOutputFromModules({
  29. [MODULE]: modules[MODULE],
  30. })
  31. }
  32. return formatOutputFromModules(modules)
  33. }
  34. module.exports = {
  35. entry: modulesToBuild(),
  36. output: {
  37. // Step away from the src folder and extract to the js folder
  38. path: path.join(__dirname, 'dist'),
  39. // Let webpack determine automatically where it's located
  40. publicPath: 'auto',
  41. filename: '[name].js?v=[contenthash]',
  42. chunkFilename: '[name]-[id].js?v=[contenthash]',
  43. // Make sure sourcemaps have a proper path and do not
  44. // leak local paths https://github.com/webpack/webpack/issues/3603
  45. devtoolNamespace: 'nextcloud',
  46. devtoolModuleFilenameTemplate(info) {
  47. const rootDir = process.cwd()
  48. const rel = path.relative(rootDir, info.absoluteResourcePath)
  49. return `webpack:///nextcloud/${rel}`
  50. },
  51. },
  52. module: {
  53. rules: [
  54. {
  55. test: /davclient/,
  56. loader: 'exports-loader',
  57. options: {
  58. type: 'commonjs',
  59. exports: 'dav',
  60. },
  61. },
  62. {
  63. test: /\.css$/,
  64. use: ['style-loader', 'css-loader'],
  65. },
  66. {
  67. test: /\.scss$/,
  68. use: ['style-loader', 'css-loader', 'sass-loader'],
  69. },
  70. {
  71. test: /\.vue$/,
  72. loader: 'vue-loader',
  73. exclude: BabelLoaderExcludeNodeModulesExcept([
  74. 'vue-material-design-icons',
  75. ]),
  76. },
  77. {
  78. test: /\.js$/,
  79. loader: 'babel-loader',
  80. // automatically detect necessary packages to
  81. // transpile in the node_modules folder
  82. exclude: BabelLoaderExcludeNodeModulesExcept([
  83. '@nextcloud/dialogs',
  84. '@nextcloud/event-bus',
  85. '@nextcloud/vue-dashboard',
  86. 'davclient.js',
  87. 'nextcloud-vue-collections',
  88. 'p-finally',
  89. 'p-limit',
  90. 'p-locate',
  91. 'p-queue',
  92. 'p-timeout',
  93. 'p-try',
  94. 'semver',
  95. 'striptags',
  96. 'toastify-js',
  97. 'v-tooltip',
  98. 'yocto-queue',
  99. ]),
  100. },
  101. {
  102. test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
  103. loader: 'url-loader',
  104. options: {
  105. name: '[name].[ext]?[hash]',
  106. },
  107. },
  108. {
  109. test: /\.handlebars/,
  110. loader: 'handlebars-loader',
  111. },
  112. ],
  113. },
  114. optimization: {
  115. splitChunks: {
  116. automaticNameDelimiter: '-',
  117. cacheGroups: {
  118. vendors: {
  119. // split every dependency into one bundle
  120. test: /[\\/]node_modules[\\/]/,
  121. enforce: true,
  122. // necessary to keep this name to properly inject it
  123. // see OC_Template.php
  124. name: 'core-common',
  125. chunks: 'all',
  126. },
  127. },
  128. },
  129. },
  130. plugins: [
  131. new VueLoaderPlugin(),
  132. new ESLintPlugin(),
  133. new webpack.ProvidePlugin({
  134. // Provide jQuery to jquery plugins as some are loaded before $ is exposed globally.
  135. jQuery: 'jquery',
  136. }),
  137. ],
  138. resolve: {
  139. alias: {
  140. // make sure to use the handlebar runtime when importing
  141. handlebars: 'handlebars/runtime',
  142. },
  143. extensions: ['*', '.js', '.vue'],
  144. symlinks: false,
  145. fallback: {
  146. stream: require.resolve('stream-browserify'),
  147. buffer: require.resolve('buffer'),
  148. },
  149. },
  150. }