search

Home  >  Q&A  >  body text

babel-loader not working? webpack

Babel-loader is used to convert es6 code in webpack2, but the expected results are not seen in the final bundle.js. There are still es6 syntax, let, and default function parameter values. .

The following is the configuration part of my webpack:

var path = require("path");
var vuxLoader = require('vux-loader');
var webpack = require('webpack');

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

var webpackConfig = {
    entry: {
        // app: ["./app/cart.js"]
        app: ["./app/goodsDetail.js"]
        // app: ["./app/center.js"]
    },
      output: {
        path: path.resolve(__dirname, "build"),
        publicPath: "/",
        filename: "bundle.js"
     },
     module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                      // vue-loader options
                   }
              },
              {
              test: /\.js?$/,
              // exclude: /node_modules/,
              exclude: /node_modules/,
              loader: 'babel',
              query: {
                      presets: ['env']
                }
            }
        ]
    },
      resolve: {
        extensions: ['.js', '.vue', '.json']
    },
    devServer: {
        host: '0.0.0.0'
    },
    plugins: [
        new webpack.DefinePlugin({
          'process.env': {
            NODE_ENV: '"production"'
          }
        })
      ]
};

module.exports = vuxLoader.merge(webpackConfig,{
    plugins: ['vux-ui']
});

I searched and searched but could not find the reason. . .

我想大声告诉你我想大声告诉你2835 days ago705

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-18 11:03:26

    Please create a new one
    .babelrc

    in the project root directory
    {
        "presets": ["env"]
    }

    reply
    0
  • 迷茫

    迷茫2017-05-18 11:03:26

    babel: {
            presets: ['es2015', 'stage-2']
        }
        加上这部分试试

    reply
    0
  • Cancelreply