简体   繁体   English

babel-loader仅用于将es6转换为es5?

[英]babel-loader only for transpiling es6 to es5?

I use babel-loader together with Webpack to transpile JavaScript es6 to es5. 我将babel-loader和Webpack一起使用将JavaScript es6转换为es5。 Is it though possible to do the opposite? 是否有可能做相反的事情? Transpile everything to es6? 将所有内容传送到es6? If not, is there another proven Webpack loader (for development or production) for that? 如果不是,是否还有其他经过验证的Webpack加载器(用于开发或生产)?

Versions I use (package.json): 我使用的版本(package.json):

"devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "ts-loader": "^4.2.0",
    "typescript": "^2.8.3",
    "webpack": "^4.6.0",
    "webpack-cli": "^2.0.15",
    "webpack-dev-server": "^3.1.3"
}

My Webpack configuration: 我的Webpack配置:

const path = require('path');

const config = {
    mode: 'production',
    entry: './src/js/app.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            { test: /\.js$/, exclude: /node_modules/, use: { loader: "babel-loader" }}
        ]
    }
};

module.exports = config;

Babel cannot be used out of the box for this, you'll need some other tool. Babel不能立即使用,您需要其他一些工具。 Try https://lebab.io/ 试试https://lebab.io/

I haven't tried it to comment on the quality of resulting code. 我没有尝试过对结果代码的质量进行评论。 Imo as of now, any such tool is a risky business so be cautious. 截至目前,任何此类工具都是有风险的业务,请谨慎行事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM