webpack.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const ProvidePlugin = webpack.ProvidePlugin;
  4. const CopyPlugin = require('copy-webpack-plugin');
  5. const srcPath = path.join(__dirname, 'src');
  6. function externalCss (context, request, callback) {
  7. if (!/\.css$/.test(request)) {
  8. return callback();
  9. }
  10. const sourceFilename = path.resolve(context, request);
  11. const relativeSource = path.relative(srcPath, sourceFilename);
  12. const fileRequest = ['.', relativeSource].join(path.sep);
  13. return callback(null, `umd ${fileRequest}`);
  14. }
  15. module.exports = function (_, options) {
  16. return {
  17. stats: 'minimal',
  18. entry: {
  19. index: path.join(__dirname, 'src', 'index.js')
  20. },
  21. output: {
  22. path: path.join(__dirname, 'dist'),
  23. filename: '[name].js',
  24. libraryTarget: 'umd'
  25. },
  26. devtool: 'source-map',
  27. externals: [
  28. 'hyperapp',
  29. externalCss
  30. ],
  31. module: {
  32. rules: [
  33. {
  34. test: /\.jsx?$/,
  35. use: [
  36. {
  37. loader: 'babel-loader',
  38. options: {
  39. presets: [
  40. ['@babel/preset-env', {
  41. modules: false
  42. }]
  43. ],
  44. plugins: [
  45. ['@babel/plugin-transform-react-jsx', {
  46. pragma: 'h'
  47. }]
  48. ]
  49. }
  50. }
  51. ]
  52. }
  53. ]
  54. },
  55. plugins: [
  56. new ProvidePlugin({
  57. h: ['hyperapp', 'h']
  58. }),
  59. new CopyPlugin([
  60. {
  61. from: '**/*.css',
  62. to: './',
  63. context: 'src'
  64. }
  65. ])
  66. ]
  67. };
  68. };