webpack.conf.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const { modifyWebpackConfig, shallowMerge, defaultOptions } = require('@gera2ld/plaid');
  2. const webpack = require('webpack');
  3. const WrapperWebpackPlugin = require('wrapper-webpack-plugin');
  4. const projectConfig = require('./plaid.conf');
  5. const INIT_FUNC_NAME = 'VMInitInjection';
  6. module.exports = Promise.all([
  7. modifyWebpackConfig(async (config) => {
  8. config.plugins.push(
  9. new webpack.DefinePlugin({
  10. 'process.env.INIT_FUNC_NAME': JSON.stringify(INIT_FUNC_NAME),
  11. 'process.env.DEBUG': JSON.stringify(process.env.DEBUG || false),
  12. }),
  13. );
  14. return config;
  15. }),
  16. modifyWebpackConfig(async (config) => {
  17. config.output.libraryTarget = 'commonjs2';
  18. config.plugins.push(
  19. new WrapperWebpackPlugin({
  20. header: `\
  21. window.${INIT_FUNC_NAME} = function () {
  22. var module = { exports: {} };
  23. `,
  24. footer: `
  25. var exports = module.exports;
  26. return exports.__esModule ? exports['default'] : exports;
  27. };0;`,
  28. }),
  29. );
  30. return config;
  31. }, {
  32. projectConfig: {
  33. ...shallowMerge(defaultOptions, projectConfig),
  34. optimization: {
  35. runtimeChunk: false,
  36. splitChunks: false,
  37. },
  38. pages: {
  39. 'injected-web': {
  40. entry: './src/injected/web',
  41. },
  42. },
  43. },
  44. }),
  45. ]);