base.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  3. const ProgressBarPlugin = require('progress-bar-webpack-plugin');
  4. const path = require('path');
  5. const fs = require('fs');
  6. const webpack = require('webpack');
  7. let licenseBody = fs.readFileSync(path.resolve(__dirname, '../LICENSE'), 'utf8');
  8. licenseBody += '\nVersion: ' + process.env.HOT_VERSION;
  9. licenseBody += '\nRelease date: ' + process.env.HOT_RELEASE_DATE + ' (built at ' + process.env.HOT_BUILD_DATE + ')';
  10. module.exports.create = function create(envArgs) {
  11. const config = {
  12. devtool: false,
  13. output: {
  14. library: 'Handsontable',
  15. libraryTarget: 'umd',
  16. libraryExport: 'default',
  17. umdNamedDefine: true,
  18. path: path.resolve(__dirname, '../dist'),
  19. },
  20. resolve: {
  21. alias: {},
  22. },
  23. module: {
  24. rules: [
  25. {
  26. test: /\.css$/,
  27. loader: ExtractTextPlugin.extract({
  28. fallback: 'style-loader',
  29. use: 'css-loader',
  30. }),
  31. },
  32. {
  33. test: [
  34. // Disable loading languages from numbro and moment into final bundle
  35. /numbro\/languages/,
  36. /moment\/locale/,
  37. ],
  38. loader: path.resolve(__dirname, 'loader/empty-loader.js'),
  39. },
  40. {
  41. test: /\.js$/,
  42. loader: 'babel-loader',
  43. exclude: [
  44. /node_modules/,
  45. ],
  46. options: {
  47. cacheDirectory: false, // Disable cache. Necessary for injected variables into source code via hot.config.js
  48. },
  49. },
  50. ]
  51. },
  52. plugins: [
  53. new ProgressBarPlugin({
  54. format: ' build [:bar] \u001b[32m:percent\u001b[0m (:elapsed seconds)',
  55. summary: false,
  56. }),
  57. // This helps ensure the builds are consistent if source code hasn't changed
  58. new webpack.optimize.OccurrenceOrderPlugin(),
  59. new webpack.BannerPlugin(licenseBody),
  60. new webpack.DefinePlugin({
  61. '__ENV_ARGS__': JSON.stringify(envArgs),
  62. }),
  63. ],
  64. node: {
  65. global: false,
  66. process: false,
  67. Buffer: false,
  68. setImmediate: false,
  69. },
  70. };
  71. return [config];
  72. }