rollup babel7初始化项目避坑

 

rollup在创建node项目时候官网的说明是默认babel6 ,npm默认安装babel则是7+

 

这里初始化配置修改如下  package.json

{
  "name": "bd_log",
  "version": "1.0.0",
  "description": "改版",
  "main": "dist/bd_log.umd.js",
  "src": "src/index.js",
  "scripts": {
    "build": "npm run clean && npm run lib && rollup --config build/rollup.prod.conf.js",
    "start": "npm run dev",
    "clean": "rimraf dist/** lib/**",
    "dev": "rollup --config build/rollup.dev.conf.js -w && livereload 'dist/'",
    "test": "jest --config ./jest.conf.js --coverage"
  },
  "repository": {
    "type": "git",
    "url": "git@139.9.6.199:lbq/bd_welllog_rollup.git"
  },
  "author": "lbq",
  "license": "ISC",
  "dependencies": {
    "@babel/polyfill": "^7.8.7",
    "zrender": "^4.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.6",
    "@babel/plugin-external-helpers": "^7.8.3",
    "@babel/preset-env": "^7.9.6",
    "rollup": "^2.7.5",
    "rollup-plugin-babel": "^4.4.0",
    "rollup-plugin-commonjs": "^10.1.0",
    "rollup-plugin-json": "^4.0.0",
    "rollup-plugin-livereload": "^1.3.0",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-serve": "^1.0.1"
  }
}

 

 rollup配置代码如下

import json from 'rollup-plugin-json'
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
// import { eslint } from 'rollup-plugin-eslint'
import pkg from '../package.json'
// 压缩代码
// import uglify from 'rollup-plugin-uglify';
export default {
  input: pkg.src,
  output: {
    file: pkg.main,
    format: 'umd',
    name: 'EUtils',
    sourcemap: true,
  },

  watch: {
    include: 'src/**',
  },

  plugins: [
    resolve(),
    commonjs(),
    json(),
    // eslint({
    //   include: 'src/**',
    //   exclude: ['node_modules/**', 'dist/**'],
    // }),
    babel({
      babelrc: false,
      presets: [['@babel/env', { modules: false, loose: true }]],
      include: ['src/**', 'test/**'],
      plugins: ['@babel/plugin-external-helpers'],
      externalHelpers: true
    }),
  ],
}

  

 

posted @ 2020-05-06 23:04  Jimmy-Lee  阅读(1145)  评论(0编辑  收藏  举报