babel loader + UglifyJS的问题

时间:2017-07-27 11:56:02

标签: webpack vue.js uglifyjs

我在使用babel-loader插件和uglifyJS时遇到了一些问题。我不是这里的专家,但似乎我的ES6没有被正确地编译成es5。

我的webpack.production.js文件的内容:

var path = require("path");

var ExtractTextPlugin = require("extract-text-webpack-plugin");

var extractSass = new ExtractTextPlugin({
    filename: "[name].[contenthash].css",
    disable: true
});

var webpack = require("webpack");

module.exports = {
    entry: ['babel-polyfill', './assets/js/app.js'],
    output: {
        path: path.resolve(__dirname, "dist"),
        //publicPath: "/assets/",
        filename: 'bundle.js'
    },
    //devtool:'source-map',
    module : {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015']
                }
            }
        ],
        rules: [
            {
                test: /\.html/,
                use: [{
                    loader: "html-loader"
                }]
            },
            {
                test: /\.scss$/,
                loader: extractSass.extract({
                    use: [{
                        loader: "css-loader", options: { sourceMap : true}
                    }, {
                        loader: "sass-loader", options: { sourceMap : true}
                    }],
                    // use style-loader in development
                    fallback: "style-loader"
                })
            }
        ]
    },
    resolve: {
        mainFields: ['browserify', 'browser', 'module', 'main']
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        extractSass,
        new webpack.optimize.UglifyJsPlugin({minimize: true})
    ]
};

我的package.json:

{
  "name": "mobiile-app-template",
  "version": "1.0.0",
  "description": "A single page app template",
  "main": "app.js",
  "scripts": {
    "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js",
    "dev": "webpack-dev-server --inline --hot --host=127.0.0.1",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules --config webpack.production.config.js",
    "predeploy": "npm run build",
    "deploy": "surge --project . --domain skyy-ba.surge.sh"
  },
  "dependencies": {
    "axios": "^0.16.2",
    "babel-polyfill": "^6.23.0",
    "babel-runtime": "^6.23.0",
    "html-loader": "^0.4.4",
    "jwt-decode": "^2.2.0",
    "vee-validate": "^2.0.0-rc.5",
    "vue": "^2.1.3",
    "vue-carousel": "^0.6.4",
    "vue-router": "^2.5.3",
    "vue-simple-spinner": "^1.2.1",
    "vue-simple-upload": "^0.1.6",
    "vue-spinner": "^1.0.2",
    "vuex": "^2.3.1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "copy-webpack-plugin": "^4.0.1",
    "cross-env": "^1.0.6",
    "css-loader": "^0.26.4",
    "extract-text-webpack-plugin": "^2.1.0",
    "node-sass": "^4.5.0",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.13.2",
    "surge": "^0.18.0",
    "webpack": "^2.5.1",
    "webpack-dev-server": "^2.4.1"
  }
}

有人有什么想法吗?到目前为止尝试了许多不同的解决方案,没有运气: - (

0 个答案:

没有答案