File size: 1,856 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import path from 'path'
import * as url from 'url'

import { InputOptions, OutputOptions } from 'rollup'
import { nodeResolve as resolve } from '@rollup/plugin-node-resolve'
import * as commonjs from '@rollup/plugin-commonjs'
import * as replace from '@rollup/plugin-replace'
import * as json from '@rollup/plugin-json'
import * as polyfills from 'rollup-plugin-polyfill-node'
import { minify } from 'rollup-plugin-esbuild-minify'

import { AssetBundler } from './utils/asset-bundler.js'
import { NODE_ENV } from './utils/constants.js'

const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

const input: InputOptions = {
  input: path.join(__dirname, '../../frontend/global-entry.js'),
  plugins: [
    resolve({
      extensions: AssetBundler.DEFAULT_EXTENSIONS,
      mainFields: ['browser'],
      preferBuiltins: false,
      browser: true,
    }),
    (replace as any).default({
      'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
      'process.env.IS_BROWSER': 'true',
      'process.stderr.fd': 'false',
      preventAssignment: true,
      'process.browser': true,
    }),
    (json as any).default(),
    (commonjs as any).default(),
    (polyfills as any).default(),
    ...(NODE_ENV === 'production' ? [minify()] : []),
  ],
}

const output: OutputOptions = {
  name: 'globals',
  inlineDynamicImports: true,
  file: path.join(__dirname, `../../frontend/assets/scripts/global-bundle.${NODE_ENV}.js`),
  globals: {
    react: 'React',
    redux: 'Redux',
    axios: 'axios',
    punycode: 'punycode',
    uuid: 'uuid',
    '@adminjs/design-system/styled-components': 'styled',
    'react-dom': 'ReactDOM',
    'prop-types': 'PropTypes',
    'react-redux': 'ReactRedux',
    'react-router': 'ReactRouter',
    'react-router-dom': 'ReactRouterDOM',
  },
}

const bundler = new AssetBundler(input, output)

export default bundler