webpack.config.js 3.0 KB

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