webpack.config.js 2.9 KB

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