webpack.config.js 2.7 KB

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