webpack.common.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // problem with copy-webpack-plugin
  10. const AssetsPlugin = require('assets-webpack-plugin');
  11. const CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
  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. },
  35. resolve: {
  36. extensions: ['.js', '.json'],
  37. modules: [helpers.root('src'), helpers.root('node_modules')],
  38. },
  39. module: {
  40. rules: [
  41. {
  42. test: /.jsx?$/,
  43. exclude: /node_modules/,
  44. use: [{
  45. loader: 'babel-loader?cacheDirectory',
  46. }]
  47. },
  48. {
  49. test: /\.css$/,
  50. use: ['style-loader', 'css-loader'],
  51. // comment out 'include' spec for crowi-plugins
  52. // include: [helpers.root('resource')]
  53. },
  54. {
  55. test: /\.scss$/,
  56. use: ['style-loader', 'css-loader', 'sass-loader'],
  57. // comment out 'include' spec for crowi-plugins
  58. // include: [helpers.root('resource')]
  59. },
  60. /*
  61. * File loader for supporting images, for example, in CSS files.
  62. */
  63. {
  64. test: /\.(jpg|png|gif)$/,
  65. use: 'file-loader',
  66. },
  67. /* File loader for supporting fonts, for example, in CSS files.
  68. */
  69. {
  70. test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
  71. use: 'file-loader',
  72. }
  73. ]
  74. },
  75. plugins: [
  76. new AssetsPlugin({
  77. path: helpers.root('public/js'),
  78. filename: 'webpack-assets.json',
  79. prettyPrint: true,
  80. }),
  81. new CommonsChunkPlugin({
  82. name: 'commons',
  83. chunks: ['app', 'legacy', 'legacy-form', 'legacy-admin'],
  84. minChunks: module => /node_modules/.test(module.resource),
  85. }),
  86. new CommonsChunkPlugin({
  87. name: 'commons',
  88. chunks: ['commons', 'legacy-presentation'],
  89. }),
  90. new CommonsChunkPlugin({
  91. name: 'commons',
  92. chunks: ['commons', 'plugin'],
  93. }),
  94. new webpack.ProvidePlugin({
  95. jQuery: "jquery",
  96. $: "jquery",
  97. }),
  98. // omit moment/locale/*.js
  99. new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /ja/),
  100. ]
  101. };
  102. }