【webpack】关于配置ES6的问题
如题,这个问题从昨天一直困扰到我现在,配置了很久,网上找了不少资料,sf上也看到过一些答案,试了很多种方案,均不太满意,特来园子里请问各位大神,还望指导,谢谢!
在要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/,
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"]
]
}
报错信息
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试加上
{ test: /.js$/,
loader: "babel-loader",
query: {presets: ['es2015']},
exclude: /node_modules/
},