We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
使用插件 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。
npm run dev
npm run build
The text was updated successfully, but these errors were encountered:
No branches or pull requests
使用插件 rollup-plugin-replace
rollup.config.dev.js
使用
发布环境把调试函数置空
先赋值为空函数 noop,然后判断如果不是发布环境,就重新赋值。
noop定义
当build的时候,调试信息就不会打包。
开发版本打包
npm run dev
。发布版本打包npm run build
。The text was updated successfully, but these errors were encountered: