createConfig.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const path = require('path')
  2. const StringReplacePlugin = require('string-replace-webpack-plugin')
  3. const ExtractTextPlugin = require("extract-text-webpack-plugin")
  4. // `CheckerPlugin` is optional. Use it if you want async error reporting.
  5. // We need this plugin to detect a `--watch` mode. It may be removed later
  6. // after https://github.com/webpack/webpack/issues/3460 will be resolved.
  7. const { CheckerPlugin } = require('awesome-typescript-loader')
  8. // external configs
  9. const packageConf = require('../../package.json')
  10. /*
  11. settings:
  12. entry: { modulename: path }
  13. tsconfig: string
  14. useExternalCore: true / false (default)
  15. debug: true / false (default)
  16. */
  17. module.exports = function(/* settings, settings, settings */) {
  18. const settings = Object.assign.apply(Object, [{}].concat(Array.prototype.slice.call(arguments)))
  19. const externals = {
  20. jquery: {
  21. commonjs: 'jquery',
  22. commonjs2: 'jquery',
  23. amd: 'jquery',
  24. root: 'jQuery'
  25. },
  26. moment: 'moment'
  27. }
  28. const output = {
  29. libraryTarget: 'umd',
  30. filename: '[name].js',
  31. path: path.resolve(__dirname, '../../dist/'),
  32. devtoolModuleFilenameTemplate: 'webpack:///' + packageConf.name + '/[resource-path]'
  33. }
  34. if (!settings.useExternalCore) {
  35. output.library = 'FullCalendar';
  36. } else {
  37. externals.fullcalendar = {
  38. commonjs: 'fullcalendar',
  39. commonjs2: 'fullcalendar',
  40. amd: 'fullcalendar',
  41. root: 'FullCalendar'
  42. }
  43. }
  44. return {
  45. entry: settings.entry || {},
  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. loaders: [
  56. {
  57. test: /\.ts$/,
  58. loader: 'awesome-typescript-loader',
  59. options: {
  60. configFileName: settings.tsconfig || null
  61. }
  62. },
  63. {
  64. test: /\.ts$/,
  65. loader: StringReplacePlugin.replace({
  66. replacements: [
  67. {
  68. pattern: /<%=\s*(\w+)\s*%>/g,
  69. replacement: function(match, p1) {
  70. return packageConf[p1];
  71. }
  72. }
  73. ]
  74. })
  75. },
  76. {
  77. test: /\.css$/,
  78. loader: ExtractTextPlugin.extract({
  79. use: 'css-loader'
  80. })
  81. }
  82. ]
  83. },
  84. plugins: [
  85. new CheckerPlugin(),
  86. new StringReplacePlugin(),
  87. new ExtractTextPlugin('[name].css')
  88. ],
  89. externals: externals,
  90. devtool: settings.debug ? 'source-map' : false, // also 'inline-source-map'
  91. watch: settings.watch || false,
  92. output: output
  93. }
  94. }