2
0

webpack.config.js 3.1 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. '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. 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. options: {
  57. useCache: true
  58. }
  59. },
  60. {
  61. test: /\.css$/,
  62. loader: ExtractTextPlugin.extract([ 'css-loader' ])
  63. },
  64. {
  65. test: /\.(sass|scss)$/,
  66. loader: ExtractTextPlugin.extract([ 'css-loader', 'sass-loader' ])
  67. }
  68. ]
  69. },
  70. plugins: [
  71. new CheckerPlugin(),
  72. new ExtractTextPlugin({
  73. filename: '[name]', // the module name should already have .css in it!
  74. allChunks: true
  75. }),
  76. new webpack.BannerPlugin(BANNER)
  77. ],
  78. watchOptions: {
  79. aggregateTimeout: 100,
  80. ignored: /node_modules/
  81. },
  82. output: {
  83. library: 'FullCalendar', // gulp will strip this out for plugins
  84. libraryTarget: 'umd',
  85. filename: '[name].js',
  86. path: __dirname,
  87. devtoolModuleFilenameTemplate: 'webpack:///' + packageConfig.name + '/[resource-path]'
  88. }
  89. }
  90. /*
  91. TODO: try https://webpack.js.org/plugins/module-concatenation-plugin/
  92. */
  93. function generateLocaleMap() {
  94. const map = {}
  95. glob.sync('locale/*.js').forEach(function(path) {
  96. if (path !== 'locale/_reset.js') {
  97. // strip out .js to get module name. also, path must start with ./
  98. map['dist/' + path.replace(/\.js$/, '')] = './' + path
  99. }
  100. })
  101. map['dist/locale-all'] = Object.values(map) // all locales combined
  102. .concat([ './locale/_reset.js' ]) // for resetting back to English
  103. return map
  104. }