Convert from Webpack to Vite (#34450)
Co-authored-by: Renaud Chaput <renchap@gmail.com>
This commit is contained in:
		@@ -1,4 +1,3 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import { createRoot } from 'react-dom/client';
 | 
			
		||||
 | 
			
		||||
import Rails from '@rails/ujs';
 | 
			
		||||
@@ -273,7 +272,7 @@ async function mountReactComponent(element: Element) {
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  const { default: Component } = (await import(
 | 
			
		||||
    `@/mastodon/components/admin/${componentName}`
 | 
			
		||||
    `@/mastodon/components/admin/${componentName}.jsx`
 | 
			
		||||
  )) as { default: React.ComponentType };
 | 
			
		||||
 | 
			
		||||
  const root = createRoot(element);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,6 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import { loadLocale } from 'mastodon/locales';
 | 
			
		||||
import main from 'mastodon/main';
 | 
			
		||||
 | 
			
		||||
import { start } from '../mastodon/common';
 | 
			
		||||
import { loadLocale } from '../mastodon/locales';
 | 
			
		||||
import { loadPolyfills } from '../mastodon/polyfills';
 | 
			
		||||
 | 
			
		||||
start();
 | 
			
		||||
import { loadPolyfills } from 'mastodon/polyfills';
 | 
			
		||||
 | 
			
		||||
loadPolyfills()
 | 
			
		||||
  .then(loadLocale)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								app/javascript/entrypoints/common.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								app/javascript/entrypoints/common.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
import { start } from 'mastodon/common';
 | 
			
		||||
 | 
			
		||||
start();
 | 
			
		||||
@@ -1,15 +1,11 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import { createRoot } from 'react-dom/client';
 | 
			
		||||
 | 
			
		||||
import { afterInitialRender } from 'mastodon/hooks/useRenderSignal';
 | 
			
		||||
 | 
			
		||||
import { start } from '../mastodon/common';
 | 
			
		||||
import { Status } from '../mastodon/features/standalone/status';
 | 
			
		||||
import { loadPolyfills } from '../mastodon/polyfills';
 | 
			
		||||
import ready from '../mastodon/ready';
 | 
			
		||||
 | 
			
		||||
start();
 | 
			
		||||
 | 
			
		||||
function loaded() {
 | 
			
		||||
  const mountNode = document.getElementById('mastodon-status');
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import ready from '../mastodon/ready';
 | 
			
		||||
 | 
			
		||||
ready(() => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +0,0 @@
 | 
			
		||||
/* Placeholder file to have `inert.scss` compiled by Webpack
 | 
			
		||||
   This is used by the `wicg-inert` polyfill */
 | 
			
		||||
 | 
			
		||||
import '../styles/inert.scss';
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
import '../styles/mailer.scss';
 | 
			
		||||
 | 
			
		||||
require.context('../icons');
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
// Dynamically set webpack's loading path depending on a meta header, in order
 | 
			
		||||
// to share the same assets regardless of instance configuration.
 | 
			
		||||
// See https://webpack.js.org/guides/public-path/#on-the-fly
 | 
			
		||||
 | 
			
		||||
function removeOuterSlashes(string: string) {
 | 
			
		||||
  return string.replace(/^\/*/, '').replace(/\/*$/, '');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatPublicPath(host = '', path = '') {
 | 
			
		||||
  let formattedHost = removeOuterSlashes(host);
 | 
			
		||||
  if (formattedHost && !/^http/i.test(formattedHost)) {
 | 
			
		||||
    formattedHost = `//${formattedHost}`;
 | 
			
		||||
  }
 | 
			
		||||
  const formattedPath = removeOuterSlashes(path);
 | 
			
		||||
  return `${formattedHost}/${formattedPath}/`;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const cdnHost = document.querySelector<HTMLMetaElement>('meta[name=cdn-host]');
 | 
			
		||||
 | 
			
		||||
__webpack_public_path__ = formatPublicPath(
 | 
			
		||||
  cdnHost ? cdnHost.content : '',
 | 
			
		||||
  process.env.PUBLIC_OUTPUT_PATH,
 | 
			
		||||
);
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
import { createRoot } from 'react-dom/client';
 | 
			
		||||
 | 
			
		||||
import './public-path';
 | 
			
		||||
 | 
			
		||||
import { IntlMessageFormat } from 'intl-messageformat';
 | 
			
		||||
import type { MessageDescriptor, PrimitiveType } from 'react-intl';
 | 
			
		||||
import { defineMessages } from 'react-intl';
 | 
			
		||||
@@ -10,7 +8,6 @@ import Rails from '@rails/ujs';
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
import { throttle } from 'lodash';
 | 
			
		||||
 | 
			
		||||
import { start } from '../mastodon/common';
 | 
			
		||||
import { timeAgoString } from '../mastodon/components/relative_timestamp';
 | 
			
		||||
import emojify from '../mastodon/features/emoji/emoji';
 | 
			
		||||
import loadKeyboardExtensions from '../mastodon/load_keyboard_extensions';
 | 
			
		||||
@@ -20,8 +17,6 @@ import ready from '../mastodon/ready';
 | 
			
		||||
 | 
			
		||||
import 'cocoon-js-vanilla';
 | 
			
		||||
 | 
			
		||||
start();
 | 
			
		||||
 | 
			
		||||
const messages = defineMessages({
 | 
			
		||||
  usernameTaken: {
 | 
			
		||||
    id: 'username.taken',
 | 
			
		||||
@@ -153,9 +148,7 @@ function loaded() {
 | 
			
		||||
  const reactComponents = document.querySelectorAll('[data-component]');
 | 
			
		||||
 | 
			
		||||
  if (reactComponents.length > 0) {
 | 
			
		||||
    import(
 | 
			
		||||
      /* webpackChunkName: "containers/media_container" */ '../mastodon/containers/media_container'
 | 
			
		||||
    )
 | 
			
		||||
    import('../mastodon/containers/media_container')
 | 
			
		||||
      .then(({ default: MediaContainer }) => {
 | 
			
		||||
        reactComponents.forEach((component) => {
 | 
			
		||||
          Array.from(component.children).forEach((child) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,8 +8,6 @@ and performs no other task.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
import './public-path';
 | 
			
		||||
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
 | 
			
		||||
interface JRDLink {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,9 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import { createRoot } from 'react-dom/client';
 | 
			
		||||
 | 
			
		||||
import { start } from '../mastodon/common';
 | 
			
		||||
import ComposeContainer from '../mastodon/containers/compose_container';
 | 
			
		||||
import { loadPolyfills } from '../mastodon/polyfills';
 | 
			
		||||
import ready from '../mastodon/ready';
 | 
			
		||||
 | 
			
		||||
start();
 | 
			
		||||
 | 
			
		||||
function loaded() {
 | 
			
		||||
  const mountNode = document.getElementById('mastodon-compose');
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
import './public-path';
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
 | 
			
		||||
import ready from '../mastodon/ready';
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user