【发布时间】:2017-02-06 17:10:48
【问题描述】:
当我运行npm start (dev) Babel 是好的,所以我可以使用 es6 代码。但是当我尝试npm run-script build (prod) 时,它不使用 babel 或 es6 是无法识别的。这是我的 package.json 和 webpack-production.config.js:
{
"name": "public",
"version": "1.0.0",
"description": "",
"main": "boot.js",
"scripts": {
"start": "webpack",
"build": "webpack -p --config webpack-production.config.js",
"dev": "webpack "
},
"author": "Adevcom",
"license": "ISC",
"devDependencies": {
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-stage-0": "^6.16.0",
"babel-preset-stage-1": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"babel-preset-stage-3": "^6.17.0",
"webpack": "^1.13.3"
},
"dependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-polyfill": "^6.16.0",
"babel-preset-es2016": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-runtime": "^6.18.0",
"browserify": "^13.1.1",
"envify": "^3.4.1",
"fbjs": "^0.8.5",
"flux": "^2.1.1",
"highcharts": "^5.0.7",
"ion-rangeslider": "^2.1.4",
"keymirror": "^0.1.1",
"object-assign": "^4.1.0",
"react": "^15.3.2",
"react-cookie": "^0.4.7",
"react-dom": "^15.3.2",
"react-dropzone": "^3.7.3",
"react-dropzone-component": "^1.2.0",
"react-gemini-scrollbar": "^2.1.5",
"react-infinite": "^0.10.0",
"react-maskedinput": "^3.2.0",
"react-router": "^2.8.1",
"reactify": "^1.1.1",
"uglify-js": "^2.7.4",
"watchify": "^3.7.0"
},
"browserify": {
"transform": [
"reactify",
"envify"
]
}
}
还有:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry:['babel-polyfill',path.resolve(__dirname, "./boot.js") ] ,
output: {
path: __dirname,
filename: "bundle.js"
},
plugins: [
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('produccion'),
'TEMPORAL_PARAM': JSON.stringify('AGREGA AQUI TUS PARAMETROS PRODUCCION')
}
}),
new webpack.optimize.UglifyJsPlugin({minimize: true})
],
externals: {
// require("jquery") is external and available
// on the global var jQuery
"jquery": "jQuery"
},
devtool: 'source-map',
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" },
{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, ''),
exclude: /node_modules/,
query: {
presets: ['es2016', 'react']
}
}
]
}
};
知道为什么会这样吗?感谢您的建议。
嗯,这是 es6 工作的 webpack.congi.js:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry:[path.resolve(__dirname, "./boot.js") ] ,
output: {
path: __dirname,
filename: "bundle.js"
},
plugins: [
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('development'),
'TEMPORAL_PARAM': JSON.stringify('AGREGA AQUI TUS PARAMETROS DESARROLLO'),
'AAAAA': JSON.stringify('hola mundo desde webpack')
}
})
],
watch:true,
externals: {
// require("jquery") is external and available
// on the global var jQuery
"jquery": "jQuery"
},
// devtool: 'source-map',
module: {
loaders: [
{ test: /\.css$/, loader: "style!css" },
{
test: /\.js$/,
loader: 'babel-loader',
include: path.join(__dirname, ''),
exclude: /node_modules/,
query: {
presets: ['es2016', 'react']
}
}
]
}
};
【问题讨论】:
-
“不使用 babel 和 es6 无法识别”是什么意思?您还没有告诉我们您看到的实际问题是什么。
-
我之前提过这个问题:stackoverflow.com/questions/42071529/…我不知道发生了什么,现在我看到问题是丑化了es6代码,根据这个:github.com/webpack/webpack/issues/2972我不知道当我尝试使用 prod 环境时,为什么使用 es6 的 webpack 会出现问题。在开发环境中没有问题(因为没有被丑化)
标签: webpack ecmascript-6 babeljs