webpack.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const path = require('path')
  2. const glob = require('glob')
  3. const webpack = require('webpack')
  4. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
  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: 'ts-loader',
  62. exclude: /node_modules/,
  63. options: {
  64. transpileOnly: true // so ForkTsCheckerWebpackPlugin can take over
  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 ForkTsCheckerWebpackPlugin(),
  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('locales/*.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/locales-all'] = Object.values(map) // all locales combined
  107. return map
  108. }