webpack.config.js 2.9 KB

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