webpack.config.js 1.6 KB

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