webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const path = require('path');
  2. const fs = require('fs');
  3. const webpack = require('webpack');
  4. const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const sharedConfig = {
  7. module: {
  8. rules: [
  9. {
  10. test: /\.(woff2?|ttf|otf|eot|svg|html|ico)$/,
  11. use: [{
  12. loader: 'file-loader',
  13. options: { name: '[name].[ext]' }
  14. }]
  15. },
  16. {
  17. test: /\.(s*)css$/,
  18. use: [
  19. MiniCssExtractPlugin.loader,
  20. 'css-loader', 'resolve-url-loader', 'sass-loader'
  21. ]
  22. }
  23. ]
  24. },
  25. plugins: [
  26. new ExtraWatchWebpackPlugin({
  27. files: [
  28. './build/**/*.scss',
  29. './build/**/*.html'
  30. ],
  31. }),
  32. new webpack.DefinePlugin({
  33. __PLUGIN_VERSION_TIMESTAMP__: webpack.DefinePlugin.runtimeValue(() => `${new Date().valueOf()}`, true),
  34. __RCSB_MOLSTAR_VERSION__: webpack.DefinePlugin.runtimeValue(() => {
  35. const version = JSON.parse(fs.readFileSync('./package.json')).version;
  36. return `'${version}'`;
  37. }, true),
  38. 'process.env.DEBUG': JSON.stringify(process.env.DEBUG)
  39. }),
  40. new MiniCssExtractPlugin({ filename: 'app.css' })
  41. ],
  42. resolve: {
  43. modules: [
  44. 'node_modules',
  45. path.resolve(__dirname, 'build/src/')
  46. ],
  47. },
  48. }
  49. module.exports = [
  50. {
  51. node: { fs: 'empty' },
  52. entry: path.resolve(__dirname, `build/src/structure-viewer/index.js`),
  53. output: {
  54. library: 'app',
  55. libraryTarget: 'umd',
  56. filename: `app.js`,
  57. path: path.resolve(__dirname, `build/dist/structure-viewer`)
  58. },
  59. ...sharedConfig
  60. },
  61. ]