webpack.common.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');;
  12. /*
  13. * Webpack configuration
  14. *
  15. * See: http://webpack.github.io/docs/configuration.html#cli
  16. */
  17. module.exports = function (options) {
  18. isProd = options.env === 'production';
  19. return {
  20. entry: {
  21. 'app': './resource/js/app',
  22. 'legacy': './resource/js/legacy/crowi',
  23. 'legacy-form': './resource/js/legacy/crowi-form',
  24. 'legacy-admin': './resource/js/legacy/crowi-admin',
  25. 'legacy-presentation': './resource/js/legacy/crowi-presentation',
  26. 'plugin': './resource/js/plugin',
  27. 'style': './resource/styles',
  28. 'style-presentation': './resource/styles/presentation',
  29. },
  30. externals: {
  31. // require("jquery") is external and available
  32. // on the global var jQuery
  33. "jquery": "jQuery",
  34. "emojione": "emojione",
  35. "hljs": "hljs",
  36. },
  37. resolve: {
  38. extensions: ['.js', '.json'],
  39. modules: [helpers.root('src'), helpers.root('node_modules')],
  40. },
  41. module: {
  42. rules: [
  43. {
  44. test: /.jsx?$/,
  45. exclude: /node_modules/,
  46. use: [{
  47. loader: 'babel-loader?cacheDirectory',
  48. options: {
  49. plugins: ['lodash'],
  50. }
  51. }]
  52. },
  53. {
  54. test: /\.css$/,
  55. use: ['style-loader', 'css-loader'],
  56. // comment out 'include' spec for crowi-plugins
  57. // include: [helpers.root('resource')]
  58. },
  59. {
  60. test: /\.scss$/,
  61. use: ['style-loader', 'css-loader', 'sass-loader'],
  62. // comment out 'include' spec for crowi-plugins
  63. // include: [helpers.root('resource')]
  64. },
  65. /*
  66. * File loader for supporting images, for example, in CSS files.
  67. */
  68. {
  69. test: /\.(jpg|png|gif)$/,
  70. use: 'file-loader',
  71. },
  72. /* File loader for supporting fonts, for example, in CSS files.
  73. */
  74. {
  75. test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
  76. use: 'file-loader',
  77. }
  78. ]
  79. },
  80. plugins: [
  81. new AssetsPlugin({
  82. path: helpers.root('public/js'),
  83. filename: 'webpack-assets.json',
  84. prettyPrint: true,
  85. }),
  86. new CommonsChunkPlugin({
  87. name: 'commons',
  88. chunks: ['app', 'legacy', 'legacy-form', 'legacy-admin'],
  89. minChunks: module => /node_modules/.test(module.resource),
  90. }),
  91. new CommonsChunkPlugin({
  92. name: 'commons',
  93. chunks: ['commons', 'legacy-presentation'],
  94. }),
  95. new CommonsChunkPlugin({
  96. name: 'commons',
  97. chunks: ['commons', 'plugin'],
  98. }),
  99. new LodashModuleReplacementPlugin,
  100. // ignore
  101. new webpack.IgnorePlugin(/^\.\/lib\/deflate\.js/, /markdown-it-plantuml/),
  102. new webpack.ProvidePlugin({ // refs externals
  103. jQuery: "jquery",
  104. $: "jquery",
  105. }),
  106. ]
  107. };
  108. }