webpack.common.js 3.7 KB

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