webpack.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const webpack = require('webpack');
  2. const path = require('path');
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const fs = require('fs');
  5. module.exports = {
  6. mode: process.env['BROWSH_ENV'] === 'RELEASE' ? 'production' : 'development',
  7. target: 'node',
  8. entry: {
  9. content: './content.js',
  10. background: './background.js'
  11. },
  12. output: {
  13. path: __dirname,
  14. filename: 'dist/[name].js',
  15. },
  16. resolve: {
  17. modules: [
  18. path.resolve(__dirname, './src'),
  19. 'node_modules'
  20. ]
  21. },
  22. devtool: 'source-map',
  23. plugins: [
  24. new webpack.DefinePlugin({
  25. DEVELOPMENT: JSON.stringify(true),
  26. TEST: JSON.stringify(false),
  27. // TODO: For production use a different webpack.config.js
  28. PRODUCTION: JSON.stringify(false)
  29. }),
  30. new CopyWebpackPlugin([
  31. { from: 'assets', to: 'dist/assets' },
  32. { from: '.web-extension-id', to: 'dist/' },
  33. { from: 'manifest.json', to: 'dist/',
  34. // Inject the current Browsh version into the manifest JSON
  35. transform(manifest, _) {
  36. const version_path = '../interfacer/src/browsh/version.go';
  37. let buffer = fs.readFileSync(version_path);
  38. let version_contents = buffer.toString();
  39. const matches = version_contents.match(/"(.*?)"/);
  40. return manifest.toString().replace('BROWSH_VERSION', matches[1]);
  41. }
  42. },
  43. ])
  44. ]
  45. };