webpack.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const path = require('path')
  2. const glob = require('glob')
  3. const webpack = require('webpack')
  4. const { CheckerPlugin } = require('awesome-typescript-loader') // for https://github.com/webpack/webpack/issues/3460
  5. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  6. const packageConfig = require('./package.json')
  7. /*
  8. NOTE: js and typescript module names shouldn't have a .js extention,
  9. however, all other types of modules should.
  10. */
  11. const MODULES = {
  12. 'dist/fullcalendar': './src/main.ts',
  13. 'dist/fullcalendar.css': './src/main.scss',
  14. 'dist/fullcalendar.print.css': './src/common/print.scss',
  15. 'dist/fullcalendar-gcal': './plugins/gcal/main.ts',
  16. 'dist/fullcalendar-moment': './plugins/moment/main.ts',
  17. 'dist/fullcalendar-moment-timezone': './plugins/moment-timezone/main.ts',
  18. 'dist/fullcalendar-luxon': './plugins/luxon/main.ts',
  19. 'dist/fullcalendar-rrule': './plugins/rrule/main.ts',
  20. 'tmp/automated-tests': './tests/automated/index'
  21. }
  22. const BANNER =
  23. '<%= title %> v<%= version %>\n' +
  24. 'Docs & License: <%= homepage %>\n' +
  25. '(c) <%= copyright %>'
  26. module.exports = {
  27. entry: Object.assign({}, MODULES, generateLocaleMap()),
  28. externals: {
  29. superagent: 'superagent',
  30. moment: 'moment',
  31. 'moment-timezone': 'moment-timezone',
  32. luxon: 'luxon',
  33. rrule: 'rrule',
  34. dragula: 'dragula',
  35. // for plugins that might need jQuery
  36. jquery: {
  37. commonjs: 'jquery',
  38. commonjs2: 'jquery',
  39. amd: 'jquery',
  40. root: 'jQuery'
  41. },
  42. // plugins reference the root 'fullcalendar' namespace
  43. fullcalendar: {
  44. commonjs: 'fullcalendar',
  45. commonjs2: 'fullcalendar',
  46. amd: 'fullcalendar',
  47. root: 'FullCalendar'
  48. }
  49. },
  50. resolve: {
  51. extensions: [ '.ts', '.js' ],
  52. alias: {
  53. // use our slimmed down version
  54. // still need to npm-install the original though, for typescript transpiler
  55. tslib: path.resolve(__dirname, 'src/tslib-lite.js')
  56. }
  57. },
  58. module: {
  59. rules: [
  60. {
  61. test: /\.(ts|js)$/,
  62. loader: 'awesome-typescript-loader',
  63. options: {
  64. useCache: true
  65. }
  66. },
  67. {
  68. test: /\.css$/,
  69. loader: ExtractTextPlugin.extract([ 'css-loader' ])
  70. },
  71. {
  72. test: /\.(sass|scss)$/,
  73. loader: ExtractTextPlugin.extract([ 'css-loader', 'sass-loader' ])
  74. }
  75. ]
  76. },
  77. plugins: [
  78. new CheckerPlugin(),
  79. new ExtractTextPlugin({
  80. filename: '[name]', // the module name should already have .css in it!
  81. allChunks: true
  82. }),
  83. new webpack.BannerPlugin(BANNER)
  84. ],
  85. watchOptions: {
  86. aggregateTimeout: 100,
  87. ignored: /node_modules/
  88. },
  89. output: {
  90. library: 'FullCalendar', // gulp will strip this out for plugins
  91. libraryTarget: 'umd',
  92. filename: '[name].js',
  93. path: __dirname,
  94. devtoolModuleFilenameTemplate: 'webpack:///' + packageConfig.name + '/[resource-path]'
  95. }
  96. }
  97. /*
  98. TODO: try https://webpack.js.org/plugins/module-concatenation-plugin/
  99. */
  100. function generateLocaleMap() {
  101. const map = {}
  102. glob.sync('locale/*.js').forEach(function(path) {
  103. // strip out .js to get module name. also, path must start with ./
  104. map['dist/' + path.replace(/\.js$/, '')] = './' + path
  105. })
  106. map['dist/locale-all'] = Object.values(map) // all locales combined
  107. return map
  108. }