webpack.config.build.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. const webpack = require('webpack');
  3. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  4. const EXCLUDE_TEMPLATES = process.argv.indexOf('--exclude-templates') > -1;
  5. const MIN = process.argv.indexOf('-p') > -1;
  6. let cssFilename, jsFilename;
  7. jsFilename = cssFilename = 'angular-bootstrap-calendar';
  8. if (!EXCLUDE_TEMPLATES) {
  9. jsFilename += '-tpls';
  10. }
  11. if (MIN) {
  12. jsFilename += '.min';
  13. cssFilename += '.min';
  14. }
  15. jsFilename += '.js';
  16. cssFilename += '.css';
  17. function getBanner() {
  18. const pkg = require('./bower.json');
  19. return `
  20. /**
  21. * ${pkg.name} - ${pkg.description}
  22. * @version v${pkg.version}
  23. * @link ${pkg.homepage}
  24. * @license ${pkg.license}
  25. */
  26. `.trim();
  27. }
  28. module.exports = {
  29. entry: __dirname + '/src/entry.js',
  30. output: {
  31. path: __dirname + '/dist/js',
  32. filename: jsFilename,
  33. libraryTarget: 'umd',
  34. library: 'angularBootstrapCalendarModuleName'
  35. },
  36. externals: {
  37. angular: 'angular',
  38. moment: 'moment',
  39. 'interact.js': {
  40. root: 'interact',
  41. commonjs: 'interact.js',
  42. commonjs2: 'interact.js',
  43. amd: 'interact'
  44. }
  45. },
  46. devtool: MIN ? 'source-map' : null,
  47. module: {
  48. preLoaders: [{
  49. test: /.*\.js$/,
  50. loaders: ['eslint'],
  51. exclude: /node_modules/
  52. }, {
  53. test: /\.html$/,
  54. loader: 'htmlhint',
  55. exclude: /node_modules/
  56. }],
  57. loaders: [{
  58. test: /.*\.js$/,
  59. loaders: ['ng-annotate'],
  60. exclude: /node_modules/
  61. }, {
  62. test: /\.html$/,
  63. loader: 'html',
  64. exclude: /node_modules/
  65. }, {
  66. test: /\.less$/,
  67. loader: ExtractTextPlugin.extract('style-loader', 'css?sourceMap!less?sourceMap'),
  68. exclude: /node_modules/
  69. }]
  70. },
  71. plugins: [
  72. new webpack.NoErrorsPlugin(),
  73. new webpack.BannerPlugin(getBanner(), {
  74. raw: true,
  75. entryOnly: true
  76. }),
  77. new ExtractTextPlugin('../css/' + cssFilename),
  78. new webpack.DefinePlugin({
  79. EXCLUDE_TEMPLATES: EXCLUDE_TEMPLATES
  80. })
  81. ]
  82. };
  83. if (EXCLUDE_TEMPLATES) {
  84. module.exports.plugins.push(new webpack.IgnorePlugin(/templates\/(.+)\.html$/));
  85. }