webpack.common.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 ExtractTextPlugin = require('extract-text-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/scss/style.scss',
  28. 'style-theme-default': './resource/styles/scss/theme/default.scss',
  29. 'style-theme-default-dark': './resource/styles/scss/theme/default-dark.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. },
  43. module: {
  44. rules: [
  45. {
  46. test: /.jsx?$/,
  47. exclude: /node_modules/,
  48. use: [{
  49. loader: 'babel-loader?cacheDirectory',
  50. options: {
  51. plugins: ['lodash'],
  52. }
  53. }]
  54. },
  55. {
  56. test: /\.scss$/,
  57. use: ExtractTextPlugin.extract({
  58. fallback: 'style-loader',
  59. use: [
  60. { loader: 'css-loader', options: { minimize: isProd, sourceMap: !isProd } },
  61. { loader: 'sass-loader', options: { sourceMap: !isProd } }
  62. ]
  63. }),
  64. include: [helpers.root('resource/styles/scss')]
  65. },
  66. {
  67. test: /\.css$/,
  68. use: ['style-loader', 'css-loader'],
  69. exclude: [helpers.root('resource/styles/scss')]
  70. },
  71. {
  72. test: /\.scss$/,
  73. use: ['style-loader', 'css-loader', 'sass-loader'],
  74. exclude: [helpers.root('resource/styles/scss')]
  75. },
  76. /*
  77. * File loader for supporting images, for example, in CSS files.
  78. */
  79. {
  80. test: /\.(jpg|png|gif)$/,
  81. use: 'file-loader',
  82. },
  83. /* File loader for supporting fonts, for example, in CSS files.
  84. */
  85. {
  86. test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
  87. use: 'file-loader',
  88. }
  89. ]
  90. },
  91. plugins: [
  92. new AssetsPlugin({
  93. path: helpers.root('public/js'),
  94. filename: 'webpack-assets.json',
  95. prettyPrint: true,
  96. }),
  97. new CommonsChunkPlugin({
  98. name: 'commons',
  99. chunks: ['app', 'legacy', 'legacy-form', 'legacy-admin'],
  100. minChunks: module => /node_modules/.test(module.resource),
  101. }),
  102. new CommonsChunkPlugin({
  103. name: 'commons',
  104. chunks: ['commons', 'legacy-presentation'],
  105. }),
  106. new CommonsChunkPlugin({
  107. name: 'commons',
  108. chunks: ['commons', 'plugin'],
  109. }),
  110. // ignore
  111. new webpack.IgnorePlugin(/^\.\/lib\/deflate\.js/, /markdown-it-plantuml/),
  112. new webpack.ProvidePlugin({ // refs externals
  113. jQuery: "jquery",
  114. $: "jquery",
  115. }),
  116. ]
  117. };
  118. }