webpack.config.js 3.0 KB

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