内容纲要
import nodeResolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import run from '@rollup/plugin-run'

export default [
  {
    input: 'src/index.js',
    //external: ['ms'],
    output: [
      {
        dir: 'dest',

        //file: 'bundle.js',
        format: 'cjs',
      },
      //{ file: pkg.module, format: 'es' }
    ],
    manualChunks: {
      vendor: [
        'node_modules/express/index.js',
        'node_modules/socket.io/lib/index.js',
        'node_modules/cors/lib/index.js',
        'node_modules/axios/index.js',
        'node_modules/socket.io-client/lib/index.js',
        'node_modules/socket.io-client/dist/socket.io.js',
        'node_modules/helmet/dist/index.js',
        'node_modules/body-parser/index.js'
      ],
    },
    plugins: [
      babel({
        babelHelpers: 'bundled',
        exclude: 'node_modules/**',        
      }),
      json(),
      nodeResolve(),
      commonjs(),
      run(),
    ],
  },
]
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import scss from 'rollup-plugin-scss'
import svg from 'rollup-plugin-svg'
import { terser } from 'rollup-plugin-terser';

export default {
    input: './src/index.js',
    output: {
        file: 'build/index.js',
        format: 'cjs'
    },
    external: [ 'react' ],
    plugins: [
        babel({
            exclude: /node_modules\/.*/,
            babelHelpers: 'runtime',
            presets:[
                ["@babel/preset-env", {
                    "targets": {
                        "ie": 8
                    },
                    "modules": false
                }],
            ],
            plugins: [['@babel/plugin-transform-runtime', { useESModules: false }]]
        }),
        json(),
        resolve(),
        commonjs(),
        scss({
            output: true
        }),
        svg(),
        terser({
            output: {
                comments: false
            }
        })

    ]
};

typescript

import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import { terser } from "rollup-plugin-terser";

export default {
  input: "src/index.tsx",

  output: {
    dir: "docs",
    format: "es",
    sourcemap: true,
  },

  plugins: [
    typescript(),
    babel({ extensions: [".js", ".ts", ".tsx"] }),
    replace({
      "process.env.NODE_ENV": JSON.stringify("production"),
    }),

    commonjs({ extensions: [".js", ".ts", ".tsx"] }),
    nodeResolve(),

    terser(),
  ],
};
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import sourcemaps from 'rollup-plugin-sourcemaps';

module.exports = {
  input: ['src/index.ts'],
  output: {
    dir: 'lib',
    format: 'cjs',
  },
  plugins: [
    resolve(),
    commonjs(),
    babel({
      babelHelpers: 'runtime',
      configFile: path.resolve(__dirname, '../../babel.config.js'),
    }),
    typescript({
      tsconfig: path.resolve(__dirname, './tsconfig.json'),
      clean: true,
    }),
    terser(),
    sourcemaps(),
  ],
};
import replace from '@rollup/plugin-replace';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import url from '@rollup/plugin-url';
import babel from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';

import pkg from './package.json';

export default [
    {
        input: 'source/index.ts',
        output: [
            {
                file: pkg.main,
                format: 'cjs',
                exports: 'named',
                sourcemap: true
            },
        ],
        inlineDynamicImports: true,
        plugins: [
            replace({
                'process.env.MODE_ENV': JSON.stringify(process.env.MODE_ENV),
            }),
            external(),
            postcss({
                modules: true,
            }),
            url(),
            babel({
                babelHelpers: 'bundled',
                exclude: 'node_modules/**',
            }),
            typescript({
                rollupCommonJSResolveHack: true,
                clean: true,
            }),
            commonjs(),
            resolve({
                modulesOnly: true,
            }),
        ],
    },
];
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
import commonjs from '@rollup/plugin-commonjs';
// compiler
import babel from '@rollup/plugin-babel';
// locates third party modules in node_modules
import resolve from '@rollup/plugin-node-resolve';
import pkg from './package.json';
// typescript
// import typescript from '@rollup/plugin-typescript';

/* resolve options */
const extensions = ['.js', '.ts', '.jsx', '.tsx'];

export default {
  input: 'src/template.ts',
  // external modules that exclude from the bundle file
  external: [],
  plugins: [
    resolve({ extensions }), // locate modules
    commonjs(), // Convert CommonJS to ES
    // typescript(), // Convert TS to JS
    babel({
      extensions,
      babelHelpers: 'bundled', // 'runtime' for building libraries with @babel/plugin-transform-runtime and @babel/runtime, 'bundled' for building application code
    }),
  ],
  output: [
    // browser-friendly UMD build
    // Browser and NodeJS
    {
      file: pkg.browser,
      format: 'umd',
      name: 'templateBabel',
    },
    // CommonJS (Node) and ES module (for bundlers) build
    {
      file: pkg.main,
      format: 'cjs',
    },
    {
      file: pkg.module,
      format: 'es',
    },
  ],
};

插件

参考

发表评论

电子邮件地址不会被公开。 必填项已用*标注