webpack.config.js 3.1 KB

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