webpack.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. watchOptions: {
  49. aggregateTimeout: 750
  50. },
  51. devtool: ''
  52. }
  53. module.exports = [
  54. {
  55. node: { fs: 'empty' },
  56. entry: path.resolve(__dirname, `build/src/structure-viewer/index.js`),
  57. output: {
  58. library: 'app',
  59. libraryTarget: 'umd',
  60. filename: `app.js`,
  61. path: path.resolve(__dirname, `build/dist/structure-viewer`)
  62. },
  63. ...sharedConfig
  64. },
  65. ]