webpack.common.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * @author: Yuki Takei <yuki@weseek.co.jp>
  3. */
  4. const webpack = require('webpack');
  5. const helpers = require('./helpers');
  6. /*
  7. * Webpack Plugins
  8. */
  9. const AssetsPlugin = require('assets-webpack-plugin');
  10. const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
  11. /*
  12. * Webpack configuration
  13. *
  14. * See: http://webpack.github.io/docs/configuration.html#cli
  15. */
  16. module.exports = function(options) {
  17. return {
  18. entry: {
  19. 'app': './resource/js/app',
  20. 'legacy': './resource/js/legacy/crowi',
  21. 'legacy-form': './resource/js/legacy/crowi-form',
  22. 'legacy-admin': './resource/js/legacy/crowi-admin',
  23. 'legacy-presentation': './resource/js/legacy/crowi-presentation',
  24. 'plugin': './resource/js/plugin',
  25. 'style': './resource/styles/scss/style.scss',
  26. 'style-theme-default': './resource/styles/scss/theme/default.scss',
  27. 'style-theme-default-dark': './resource/styles/scss/theme/default-dark.scss',
  28. 'style-theme-nature': './resource/styles/scss/theme/nature.scss',
  29. 'style-theme-mono-blue': './resource/styles/scss/theme/mono-blue.scss',
  30. 'style-theme-future': './resource/styles/scss/theme/future.scss',
  31. 'style-presentation': './resource/styles/scss/style-presentation.scss',
  32. },
  33. externals: {
  34. // require("jquery") is external and available
  35. // on the global var jQuery
  36. 'jquery': 'jQuery',
  37. 'emojione': 'emojione',
  38. 'hljs': 'hljs',
  39. },
  40. resolve: {
  41. extensions: ['.js', '.json'],
  42. modules: [helpers.root('src'), helpers.root('node_modules')],
  43. alias: {
  44. '@root': helpers.root('/'),
  45. '@alias/logger': helpers.root('lib/service/logger'),
  46. '@alias/locales': helpers.root('lib/locales'),
  47. // replace bunyan
  48. 'bunyan': 'browser-bunyan',
  49. }
  50. },
  51. module: {
  52. rules: [
  53. {
  54. test: /.jsx?$/,
  55. exclude: {
  56. test: helpers.root('node_modules'),
  57. exclude: [ // include as a result
  58. helpers.root('node_modules/string-width'),
  59. helpers.root('node_modules/is-fullwidth-code-point'), // depends from string-width
  60. ]
  61. },
  62. use: [{
  63. loader: 'babel-loader?cacheDirectory',
  64. options: {
  65. plugins: ['lodash'],
  66. }
  67. }]
  68. },
  69. {
  70. test: /locales/,
  71. loader: '@alienfast/i18next-loader',
  72. options: {
  73. basenameAsNamespace: true,
  74. }
  75. },
  76. {
  77. test: /\.css$/,
  78. use: ['style-loader', 'css-loader'],
  79. exclude: [helpers.root('resource/styles/scss')]
  80. },
  81. {
  82. test: /\.scss$/,
  83. use: ['style-loader', 'css-loader', 'sass-loader'],
  84. exclude: [helpers.root('resource/styles/scss')]
  85. },
  86. /*
  87. * File loader for supporting images, for example, in CSS files.
  88. */
  89. {
  90. test: /\.(jpg|png|gif)$/,
  91. use: 'file-loader',
  92. },
  93. /* File loader for supporting fonts, for example, in CSS files.
  94. */
  95. {
  96. test: /\.(eot|woff2?|svg|ttf)([?]?.*)$/,
  97. use: 'file-loader',
  98. }
  99. ]
  100. },
  101. plugins: [
  102. new AssetsPlugin({
  103. path: helpers.root('public/js'),
  104. filename: 'webpack-assets.json',
  105. prettyPrint: true,
  106. }),
  107. new CommonsChunkPlugin({
  108. name: 'commons',
  109. chunks: ['app', 'legacy', 'legacy-form', 'legacy-admin'],
  110. minChunks: module => /node_modules/.test(module.resource),
  111. }),
  112. new CommonsChunkPlugin({
  113. name: 'commons',
  114. chunks: ['commons', 'legacy-presentation'],
  115. }),
  116. new CommonsChunkPlugin({
  117. name: 'commons',
  118. chunks: ['commons', 'plugin'],
  119. }),
  120. // ignore
  121. new webpack.IgnorePlugin(/^\.\/lib\/deflate\.js/, /markdown-it-plantuml/),
  122. new webpack.ProvidePlugin({ // refs externals
  123. jQuery: 'jquery',
  124. $: 'jquery',
  125. }),
  126. ]
  127. };
  128. };