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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 modules = require('./webpack.modules.js')
  7. const modulesToBuild = () => {
  8. const MODULE = process.env.MODULE
  9. if (MODULE) {
  10. if (!modules[MODULE]) {
  11. throw new Error(`No module "${MODULE}" found`)
  12. }
  13. return modules[MODULE]
  14. }
  15. // merge all configs into one object
  16. return Object.assign({}, ...Object.values(modules))
  17. }
  18. module.exports = {
  19. entry: modulesToBuild(),
  20. output: {
  21. // Step away from the src folder and extract to the js folder
  22. path: path.join(__dirname),
  23. publicPath: '/dist/',
  24. filename: (chunkData) => {
  25. // Get relative path of the src folder
  26. const srcPath = chunkData.chunk.entryModule.context
  27. const relativePath = path.relative(__dirname, srcPath)
  28. // If this is a core source, output in core dist folder
  29. if (relativePath.indexOf('core/src') > -1) {
  30. return path.join('core/js/dist/', '[name].js?v=[contenthash]')
  31. }
  32. // Get out of the shared dist folder and output inside apps js folder
  33. return path.join(relativePath, '..', 'js') + '/[name].js?v=[contenthash]'
  34. },
  35. chunkFilename: 'dist/[name]-[id].js?v=[contenthash]',
  36. },
  37. module: {
  38. rules: [
  39. {
  40. test: /\.css$/,
  41. use: ['style-loader', 'css-loader'],
  42. },
  43. {
  44. test: /\.scss$/,
  45. use: ['style-loader', 'css-loader', 'sass-loader'],
  46. },
  47. {
  48. test: /\.vue$/,
  49. loader: 'vue-loader',
  50. exclude: BabelLoaderExcludeNodeModulesExcept([
  51. 'vue-material-design-icons',
  52. ]),
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: 'babel-loader',
  57. // automatically detect necessary packages to
  58. // transpile in the node_modules folder
  59. exclude: BabelLoaderExcludeNodeModulesExcept([
  60. '@nextcloud/dialogs',
  61. '@nextcloud/event-bus',
  62. '@nextcloud/vue-dashboard',
  63. 'davclient.js',
  64. 'nextcloud-vue-collections',
  65. 'p-finally',
  66. 'p-limit',
  67. 'p-locate',
  68. 'p-queue',
  69. 'p-timeout',
  70. 'p-try',
  71. 'semver',
  72. 'striptags',
  73. 'toastify-js',
  74. 'v-tooltip',
  75. 'yocto-queue',
  76. ]),
  77. },
  78. {
  79. test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf)$/,
  80. loader: 'url-loader',
  81. options: {
  82. name: '[name].[ext]?[hash]',
  83. },
  84. },
  85. {
  86. test: /\.handlebars/,
  87. loader: 'handlebars-loader',
  88. query: {
  89. extensions: '.handlebars',
  90. },
  91. },
  92. ],
  93. },
  94. optimization: {
  95. splitChunks: {
  96. automaticNameDelimiter: '-',
  97. cacheGroups: {
  98. vendors: {
  99. test: /[\\/]node_modules[\\/]/,
  100. enforce: true,
  101. name: 'nextcloud',
  102. chunks: 'all',
  103. },
  104. },
  105. },
  106. },
  107. plugins: [new VueLoaderPlugin(), new ESLintPlugin()],
  108. resolve: {
  109. alias: {
  110. OC: path.resolve(__dirname, './core/src/OC'),
  111. OCA: path.resolve(__dirname, './core/src/OCA'),
  112. // make sure to use the handlebar runtime when importing
  113. handlebars: 'handlebars/runtime',
  114. },
  115. extensions: ['*', '.js', '.vue'],
  116. symlinks: false,
  117. },
  118. }