-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
使用插件 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
。
Metadata
Metadata
Assignees
Labels
No labels