简体   繁体   中英

babel-loader only for transpiling es6 to es5?

I use babel-loader together with Webpack to transpile JavaScript es6 to es5. Is it though possible to do the opposite? Transpile everything to es6? If not, is there another proven Webpack loader (for development or production) for that?

Versions I use (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:

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. Try 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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