【Rollup】Rollup发布npm包

335 阅读1分钟

rollup.config.js

// import { uglify } from "rollup-plugin-uglify";
// import replace from "rollup-plugin-replace";
// import json from "rollup-plugin-json";
// import clear from "rollup-plugin-clear";
// import { eslint } from "rollup-plugin-eslint";
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import postcss from 'rollup-plugin-postcss'
import resolve from 'rollup-plugin-node-resolve'
import typescript from 'rollup-plugin-typescript'
import url from 'rollup-plugin-url'
import babel from 'rollup-plugin-babel'
import sass from 'node-sass'
import autoprefixer from 'autoprefixer'
import postcssurl from 'postcss-url'
import pkg from './package.json'
export default {
  input: 'src/index.ts',
  output: [
    {
      file: pkg.main,
      format: 'cjs'
    }, {
      file: pkg.module,
      format: 'es'
    }
 ], 
 plugins: [
    external(),
    postcss({
      preprocessor: (content, id) => new Promise(res => {
        const result = sass.renderSync({ file: id })
        res({ code: result.css.toString() })
      }),
      plugins: [autoprefixer, postcssurl({ url: 'inline' })],
      minimize: true,
      // extract: true,
      extensions: ['.sass', '.css']
    }),
    typescript(),
    url({
      limit: 10 * 1024, // inline files < 10k, copy files > 10k
      publicPath: '/',
      emitFiles: true // defaults to true
    }), babel({
      exclude: ["node_modules/**"],
      extensions: ["tsx","ts","js","jsx"]//超级关键配置 }),
    resolve({
      extensions: ['.ts', '.tsx', '.json']
    }),
    commonjs() ]
}

.babelrc

{
  "presets": [

    [
      "@babel/preset-react"
    ]
  ]
}

package.json

{
    "name": "@deyi/ibt-img",
    "version": "1.0.0",
    "description": "react image component",
    "main": "dist/index.js",
    "module": "dist/index.esm.js",
    "types": "./index.d.ts",
    "keywords": [
        "react",
        "image",
        "component"
    ], "files": [
        "dist",
        "es",
        "src",
        "index.d.ts"
    ],
    "scripts": {
        "build": "rollup -c",
        "tslint": "tslint --fix --format codeFrame --project .",
        "pub": "npm run build && npm publish"
    },
    "author": "",
    "license": "MIT",
    "homepage": "https://git.com/nikangdi/ibt-img",
    "repository": {
        "type": "git",
        "url": "https://git.com/nikangdi/ibt-img.git"
    },
    "bugs": {
        "url": "https://git.com/nikangdi/ibt-img/issues"
    },
    "peerDependencies": {

"react": ">=16.0.0",
    "react-dom": ">=16.0.0"
},

"devDependencies": {
        "@babel/core": "^7.5.5",
        "@babel/preset-env": "^7.10.2",
        "@babel/preset-react": "^7.10.1",
        "@babel/preset-typescript": "^7.10.1",
        "@poi/plugin-typescript": "^12.0.1",
        "@rollup/plugin-babel": "^5.0.3",
        "@rollup/plugin-commonjs": "^13.0.0",
        "@rollup/plugin-node-resolve": "^8.0.1",
        "@rollup/plugin-replace": "^2.3.3",
        "@types/enzyme": "^3.1.15",
        "@types/enzyme-adapter-react-16": "^1.0.3",
        "@types/node": "^11.10.4",
        "@types/react": "^16.7.6",
        "autoprefixer": "^9.1.5",
        "babel-core": "^6.26.3",
        "babel-plugin-external-helpers": "^6.22.0",
        "babel-plugin-import": "^1.12.0",
        "babel-preset-env": "^1.7.0",
        "babel-preset-flow": "^6.23.0",
        "enzyme": "^3.7.0",
        "enzyme-adapter-react-16": "^1.6.0",
        "node-sass": "^4.9.2",
        "poi": "^12.5.5",
        "postcss-import": "^12.0.1",
        "postcss-loader": "^3.0.0",
        "postcss-url": "^8.0.0",
        "react": "^16.5.0",
        "react-dom": "^16.5.0",
        "rollup": "^1.18.0",
        "rollup-plugin-babel": "^4.3.3",
        "rollup-plugin-clear": "^2.0.7",
        "rollup-plugin-commonjs": "^10.0.1",
        "rollup-plugin-eslint": "^7.0.0",
        "rollup-plugin-flow": "^1.1.1",
        "rollup-plugin-image": "^1.0.2",
        "rollup-plugin-json": "^4.0.0",
        "rollup-plugin-node-resolve": "^5.2.0",
        "rollup-plugin-peer-deps-external": "^2.2.0",
        "rollup-plugin-postcss": "^2.9.0",
        "rollup-plugin-replace": "^2.2.0",
        "rollup-plugin-typescript": "^1.0.1",
        "rollup-plugin-uglify": "^6.0.2",
        "rollup-plugin-url": "^2.2.2",
        "tslint": "^5.11.0",
        "tslint-config-prettier": "^1.16.0",
        "tslint-eslint-rules": "^5.4.0",
        "tslint-react": "^3.6.0",
        "typescript": "^3.1.6"
    },
    "dependencies": {
    }
}