You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

webpack.common.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. clean: true,
  52. },
  53. module: {
  54. rules: [
  55. {
  56. test: /davclient/,
  57. loader: 'exports-loader',
  58. options: {
  59. type: 'commonjs',
  60. exports: 'dav',
  61. },
  62. },
  63. {
  64. test: /\.css$/,
  65. use: ['style-loader', 'css-loader'],
  66. },
  67. {
  68. test: /\.scss$/,
  69. use: ['style-loader', 'css-loader', 'sass-loader'],
  70. },
  71. {
  72. test: /\.vue$/,
  73. loader: 'vue-loader',
  74. exclude: BabelLoaderExcludeNodeModulesExcept([
  75. 'vue-material-design-icons',
  76. ]),
  77. },
  78. {
  79. test: /\.js$/,
  80. loader: 'babel-loader',
  81. // automatically detect necessary packages to
  82. // transpile in the node_modules folder
  83. exclude: BabelLoaderExcludeNodeModulesExcept([
  84. '@nextcloud/dialogs',
  85. '@nextcloud/event-bus',
  86. '@nextcloud/vue-dashboard',
  87. 'davclient.js',
  88. 'nextcloud-vue-collections',
  89. 'p-finally',
  90. 'p-limit',
  91. 'p-locate',
  92. 'p-queue',
  93. 'p-timeout',
  94. 'p-try',
  95. 'semver',
  96. 'striptags',
  97. 'toastify-js',
  98. 'v-tooltip',
  99. 'yocto-queue',
  100. ]),
  101. },
  102. {
  103. test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
  104. loader: 'url-loader',
  105. options: {
  106. name: '[name].[ext]?[hash]',
  107. },
  108. },
  109. {
  110. test: /\.handlebars/,
  111. loader: 'handlebars-loader',
  112. },
  113. ],
  114. },
  115. optimization: {
  116. splitChunks: {
  117. automaticNameDelimiter: '-',
  118. cacheGroups: {
  119. vendors: {
  120. // split every dependency into one bundle
  121. test: /[\\/]node_modules[\\/]/,
  122. enforce: true,
  123. // necessary to keep this name to properly inject it
  124. // see OC_Template.php
  125. name: 'core-common',
  126. chunks: 'all',
  127. },
  128. },
  129. },
  130. },
  131. plugins: [
  132. new VueLoaderPlugin(),
  133. new ESLintPlugin(),
  134. new webpack.ProvidePlugin({
  135. // Provide jQuery to jquery plugins as some are loaded before $ is exposed globally.
  136. jQuery: 'jquery',
  137. }),
  138. ],
  139. resolve: {
  140. alias: {
  141. // make sure to use the handlebar runtime when importing
  142. handlebars: 'handlebars/runtime',
  143. },
  144. extensions: ['*', '.js', '.vue'],
  145. symlinks: false,
  146. fallback: {
  147. stream: require.resolve('stream-browserify'),
  148. buffer: require.resolve('buffer'),
  149. },
  150. },
  151. }