egoist / bili

Bili makes it easier to bundle JavaScript libraries.

Home Page:https://bili.egoist.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I import commonjs module in typescript project?

shanmugapriyaEK opened this issue · comments

Thanks a lot for saving my development time.
I am using bili in my typescript player library project.

I want to import Shaka player in my typescript. Shaka player does not have types.
'https://github.com/google/shaka-player'
But I am unable to import it.

Bili config

const config: Config = {
  globals: {
    shaka: 'shaka',
  },
  resolvePlugins: {
    'shaka-player': require('./packages/XXX/node_modules/shaka-player/dist/shaka-player.compiled'),
  },
  plugins: {
    ['node-resolve']: {
      jsnext: true,
      preferBuiltins: true,
      browser: true,
    },
    typescript2: {
      cacheRoot: path.join(__dirname, '.rpt2_cache'),
      useTsconfigDeclarationDir: true,
    },
    commonjs: {
      namedExports: {
        'shaka-player': ['shaka'],
      },
    },
    terser: {
      mangle: {
        properties: {
          regex: /_$/,
          // regex: /_[a-zA-Z0-9(,)]*/,
        },
      },
    },
  },
  input: 'packages/xxx/lib/index.ts',
  env: {
    NODE_ENV: 'production',
    SDK_VERSION: JSON.stringify(require('./package.json').version),
  },
  output: {
    format: ['iife-min', 'esm-min'],
    moduleName: 'xxx',
    dir: './dist',
  },
  
};
export default config;