Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

01 编译环境搭建2 引入开发和发布环境打包脚本 #2

Open
xwjie opened this issue Jan 3, 2018 · 0 comments
Open

01 编译环境搭建2 引入开发和发布环境打包脚本 #2

xwjie opened this issue Jan 3, 2018 · 0 comments

Comments

@xwjie
Copy link
Owner

xwjie commented Jan 3, 2018

使用插件 rollup-plugin-replace

rollup.config.dev.js

import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace'

export default [{
  input: 'src/main.js',
  output: {
    file: 'dist/xiao.js',
    format: 'umd',
    name: 'Xiao'
  },
  plugins: [ 
  	resolve(),
    babel({
      exclude: 'node_modules/**' // only transpile our source code
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify('development'),
    }),
  ]
}];

使用

if (process.env.NODE_ENV !== 'production'  ) {
    warn(' some message')
  }

发布环境把调试函数置空

先赋值为空函数 noop,然后判断如果不是发布环境,就重新赋值。

import { noop } from '../shared/util'

export let warn = noop

if (process.env.NODE_ENV !== 'production') {
  warn = (msg) => {
    console.error(`[Xiao warn]: ${msg}`)
  }
}

noop定义

export function noop (a?: any, b?: any, c?: any) {}

当build的时候,调试信息就不会打包。

开发版本打包 npm run dev。发布版本打包 npm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant