RE:babel nodejs 语法提升es7 标准用法

技术分享 2019-10-01 00:00:00
babel v5 v6 v7 版本间差别很大并且不很兼容,以官方的文档为标准吧有事还得做插件


直接用 babel-node 运行不适合在生产环境中,会多出很多资源消耗,但是开发环境无所谓啦,生产环境需要将转换完成的的es5结果部署

更好的方案是用 webpack 打包成一个js文件,打包过程还支持babel翻译

package.json "scripts": {
"test": "npx babel-node index",
"build": "npx webpack-cli"
},

webpackage.config.js


//const path = require('path');
let nodeExternals = require('webpack-node-externals');
module.exports = {
context: __dirname,
target: 'node', // in order to ignore built-in modules like path, fs, etc.
externals: , // in order to ignore all modules in node_modules folder
entry: './src/index.js',
output: {
filename: 'main.js',
path: __dirname
//path: path.resolve(__dirname, 'dist')
},
mode: 'production',
module: {
rules:
]
}
},
exclude: '/node_modules/'
}
]
}
};





生产环境只需要上传 main.js 即可
咨询小瓶科技
咨询我们
顶部