resolveAppConfig.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module.exports = (api, args, options) => {
  2. const config = api.resolveChainableWebpackConfig()
  3. const targetDir = api.resolve(args.dest || options.outputDir)
  4. // respect inline build destination in copy plugin
  5. if (args.dest && config.plugins.has('copy')) {
  6. config.plugin('copy').tap(pluginArgs => {
  7. pluginArgs[0][0].to = targetDir
  8. return pluginArgs
  9. })
  10. }
  11. if (args.modern) {
  12. const ModernModePlugin = require('../../webpack/ModernModePlugin')
  13. if (!args.modernBuild) {
  14. // Inject plugin to extract build stats and write to disk
  15. config
  16. .plugin('modern-mode-legacy')
  17. .use(ModernModePlugin, [{
  18. targetDir,
  19. isModernBuild: false,
  20. unsafeInline: args['unsafe-inline']
  21. }])
  22. } else {
  23. // Inject plugin to read non-modern build stats and inject HTML
  24. config
  25. .plugin('modern-mode-modern')
  26. .use(ModernModePlugin, [{
  27. targetDir,
  28. isModernBuild: true,
  29. unsafeInline: args['unsafe-inline'],
  30. // as we may generate an addition file asset (if `no-unsafe-inline` specified)
  31. // we need to provide the correct directory for that file to place in
  32. jsDirectory: require('../../util/getAssetPath')(options, 'js')
  33. }])
  34. }
  35. }
  36. const rawConfig = api.resolveWebpackConfig(config)
  37. // respect inline entry
  38. if (args.entry && !options.pages) {
  39. const entry = api.resolve(args.entry)
  40. rawConfig.entry = { app: entry }
  41. process.env.VUE_CLI_ENTRY_FILES = JSON.stringify([entry])
  42. }
  43. return rawConfig
  44. }