webpack.common.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-theme-blue-night': './resource/styles/scss/theme/blue-night.scss',
  32. 'style-presentation': './resource/styles/scss/style-presentation.scss',
  33. },
  34. externals: {
  35. // require("jquery") is external and available
  36. // on the global var jQuery
  37. 'jquery': 'jQuery',
  38. 'emojione': 'emojione',
  39. 'hljs': 'hljs',
  40. },
  41. resolve: {
  42. extensions: ['.js', '.json'],
  43. modules: [helpers.root('src'), helpers.root('node_modules')],
  44. alias: {
  45. '@root': helpers.root('/'),
  46. '@alias/logger': helpers.root('lib/service/logger'),
  47. '@alias/locales': helpers.root('lib/locales'),
  48. // replace bunyan
  49. 'bunyan': 'browser-bunyan',
  50. }
  51. },
  52. module: {
  53. rules: [
  54. {
  55. test: /.jsx?$/,
  56. exclude: {
  57. test: helpers.root('node_modules'),
  58. exclude: [ // include as a result
  59. helpers.root('node_modules/string-width'),
  60. helpers.root('node_modules/is-fullwidth-code-point'), // depends from string-width
  61. ]
  62. },
  63. use: [{
  64. loader: 'babel-loader?cacheDirectory',
  65. options: {
  66. plugins: ['lodash'],
  67. }
  68. }]
  69. },
  70. {
  71. test: /locales/,
  72. loader: '@alienfast/i18next-loader',
  73. options: {
  74. basenameAsNamespace: true,
  75. }
  76. },
  77. {
  78. test: /\.css$/,
  79. use: ['style-loader', 'css-loader'],
  80. exclude: [helpers.root('resource/styles/scss')]
  81. },
  82. {
  83. test: /\.scss$/,
  84. use: ['style-loader', 'css-loader', 'sass-loader'],
  85. exclude: [helpers.root('resource/styles/scss')]
  86. },
  87. /*
  88. * File loader for supporting images, for example, in CSS files.
  89. */
  90. {
  91. test: /\.(jpg|png|gif)$/,
  92. use: 'file-loader',
  93. },
  94. /* File loader for supporting fonts, for example, in CSS files.
  95. */
  96. {
  97. test: /\.(eot|woff2?|svg|ttf)([?]?.*)$/,
  98. use: 'file-loader',
  99. }
  100. ]
  101. },
  102. plugins: [
  103. new AssetsPlugin({
  104. path: helpers.root('public/js'),
  105. filename: 'webpack-assets.json',
  106. prettyPrint: true,
  107. }),
  108. new CommonsChunkPlugin({
  109. name: 'commons',
  110. chunks: ['app', 'legacy', 'legacy-form', 'legacy-admin'],
  111. minChunks: module => /node_modules/.test(module.resource),
  112. }),
  113. new CommonsChunkPlugin({
  114. name: 'commons',
  115. chunks: ['commons', 'legacy-presentation'],
  116. }),
  117. new CommonsChunkPlugin({
  118. name: 'commons',
  119. chunks: ['commons', 'plugin'],
  120. }),
  121. // ignore
  122. new webpack.IgnorePlugin(/^\.\/lib\/deflate\.js/, /markdown-it-plantuml/),
  123. new webpack.ProvidePlugin({ // refs externals
  124. jQuery: 'jquery',
  125. $: 'jquery',
  126. }),
  127. ]
  128. };
  129. };