首页 新闻 会员 周边 捐助

【webpack】关于配置ES6的问题

0
悬赏园豆:5 [待解决问题]

如题,这个问题从昨天一天困扰到我现在,配置了很久,网上找了不少资料,试了很多种方案,均不太满意,特来园子里请问各位大神,分不多,还望指导,谢谢!

在要vue脚手架做了一两个项目之后,想着学一下webpack,自己配置了一番,没想到坑那么多,一步一步试错过来,但现在终究是卡在babel配置以及图片的打包上,目前还没用上多少插件。贴一下配置信息!

webpack.config.js文件

const path = require('path');
const webpack = require('webpack');

module.exports = {
    entry: './src/main.js', //入口文件
    output: { //输出
        publicPath: '/dist/',
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
     devServer: {
         port: 8092,
         inline: true,
         open: true,
         hot: true,
         historyApiFallback: true,
         noInfo: true
     },
     module: {
         rules:[
             {
                 test: /\.vue$/,
                 use:{
                     loader: 'vue-loader'
                 }
             },
             {
                 test: /\.js$/,
                 exclude: /node_modules/,
                 include: path.resolve(__dirname,'src'),
                 loader: "babel-loader",
                 options: {
                     presets: ["es2015","env"]
                 }
             },
             {
                 test: /\.css$/,
                loader: 'style-loader!css-loader'
             },
             {
                 test: /\.less$/,
                 use:{
                     loader: 'style-loader!css-loader!less-loader'
                 }
             },
            {
                test: /\.(png|jpg|jpeg|gif|svg)$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: 8192,
                        name: '[name].[ext]?[hash]'
                    }
                }]
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                      limit: 8192,
                      name: '[name].[ext]?[hash]'
                    }
                }]
            }
         ]
     },
     plugins: [
         new webpack.HotModuleReplacementPlugin(),
         new webpack.DefinePlugin({
             'process.env': {
                 NODE_ENV: '"production"'
             }
         }),
         new webpack.optimize.UglifyJsPlugin({
            sourceMap: true,
            compress: {
                warnings: false
            }
         })
     ]
}

package.json文件

{
  "name": "webpackdemo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "css-loader": "^0.28.7",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.5",
    "less": "^2.7.3",
    "less-loader": "^4.0.5",
    "style-loader": "^0.19.0",
    "uglifyjs-webpack-plugin": "^1.0.1",
    "url-loader": "^0.6.2",
    "vue": "^2.5.3",
    "vue-loader": "^13.4.0",
    "vue-router": "^3.0.1",
    "vue-template-compiler": "^2.5.3",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.4"
  },
  "scripts": {
    "dev": "webpack-dev-server --config ./webpack.config.js",
    "build": "webpack --config ./webpack.config.js --progress --colors"
  },
  "author": "len",
  "license": "ISC"
}

.babelrc文件

 

{
  "presets": [
    ["es2015", {"modules": false}],
    ["env"]
  ]
}

 

痞子Geeking的主页 痞子Geeking | 初学一级 | 园豆:9
提问于:2017-11-10 11:05
< >
分享
所有回答(1)
0

你有 .babelrc 文件,就不用给 babel-loader 配置 options 了

by.Genesis | 园豆:2824 (老鸟四级) | 2017-11-10 11:41

去掉babel-loader的options还是报错呀....

程序倒是能跑起来,但就是报错  ERR in bundl.js from UglifyJS Unexpected token:name<urlParts>...不知道是什么一个情况

支持(0) 反对(0) 痞子Geeking | 园豆:9 (初学一级) | 2017-11-10 14:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册