在webpack.optimize.UglifyJsPlugin之前将es6转换为es5
我有一个webpack应用程序,当我在开发模式下编译它时,一切都很顺利,但当我在生产模式下编译它时,我会遇到以下错误:在webpack.optimize.UglifyJsPlugin之前将es6转换为es5,webpack,babeljs,production,uglifyjs,react-boilerplate,Webpack,Babeljs,Production,Uglifyjs,React Boilerplate,我有一个webpack应用程序,当我在开发模式下编译它时,一切都很顺利,但当我在生产模式下编译它时,我会遇到以下错误: [ Error: 2.7e881e81db9016b449f9.chunk.js from UglifyJs Unexpected token: name (ptr) [2.7e881e81db9016b449f9.chunk.js:169,6] at /home/hossein/d/projects/tPlus/webClient/node_modules/ugl
[ Error: 2.7e881e81db9016b449f9.chunk.js from UglifyJs
Unexpected token: name (ptr) [2.7e881e81db9016b449f9.chunk.js:169,6]
at /home/hossein/d/projects/tPlus/webClient/node_modules/uglifyjs-webpack-plugin/dist/index.js:235:34
at Array.forEach (native)
at Compilation.<anonymous> (/home/hossein/d/projects/tPlus/webClient/node_modules/uglifyjs-webpack-plugin/dist/index.js:54:20)
at Compilation.applyPluginsAsyncSeries (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/node_modules/tapable/lib/Tapable.js:188:13)
at self.applyPluginsAsync.err (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/lib/Compilation.js:640:10)
at next (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/node_modules/tapable/lib/Tapable.js:184:11)
at ExtractTextPlugin.<anonymous> (/home/hossein/d/projects/tPlus/webClient/node_modules/extract-text-webpack-plugin/index.js:316:4)
at Compilation.applyPluginsAsyncSeries (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/node_modules/tapable/lib/Tapable.js:188:13)
at sealPart2 (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/lib/Compilation.js:636:9)
at next (/home/hossein/d/projects/tPlus/webClient/node_modules/webpack/node_modules/tapable/lib/Tapable.js:184:11)
at ExtractTextPlugin.<anonymous> (/home/hossein/d/projects/tPlus/webClient/node_modules/extract-text-webpack-plugin/index.js:292:5)
at /home/hossein/d/projects/tPlus/webClient/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:52:16
at Object.async.forEachOf.async.eachOf (/home/hossein/d/projects/tPlus/webClient/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:236:30)
这是我的webpack.base.babel.sj
:
/**
*通用网页包配置
*/
编辑
这是我从package.json
"babel": {
"presets": [
[
"latest",
{
"es2015": {
"modules": false
}
}
],
"react",
"stage-0"
],
"env": {
"production": {
"only": [
"app"
],
"plugins": [
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
},
"test": {
"plugins": [
"istanbul"
]
}
}
}
如果不知道您要传递给Babel的配置选项,则无法回答此问题。我只是编辑了我的帖子,而不知道您要传递给Babel的配置选项,则无法回答此问题。我只是编辑了我的帖子
const path = require('path');
const webpack = require('webpack');
// PostCSS plugins
const cssnext = require('postcss-cssnext');
const postcssFocus = require('postcss-focus');
const postcssReporter = require('postcss-reporter');
module.exports = (options) => ({
entry: options.entry,
externals: {
jquery: 'jQuery'
},
output: Object.assign({ // Compile into js/build.js
path: path.resolve(process.cwd(), 'build'),
publicPath: '/',
}, options.output), // Merge with env dependent settings
module: {
rules: [
{
test: /\.js$/, // Transform all .js files required somewhere with Babel
loader: 'babel-loader',
exclude: /node_modules/,
query: options.babelQuery,
}, {
// Transform our own .css files with PostCSS and CSS-modules
test: /\.css$/,
exclude: /node_modules/,
loader: options.cssLoaders,
}, {
// Do not transform vendor's CSS with CSS-modules
// The point is that they remain in global scope.
// Since we require these CSS files in our JS or CSS files,
// they will be a part of our compilation either way.
// So, no need for ExtractTextPlugin here.
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
loaders: [{
loader: "style-loader"
}, {
loader: "css-loader", options: {
sourceMap: true
}
}, {
loader: "sass-loader", options: {
sourceMap: true
}
}]
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader',
}, {
test: /\.(jpg|png|gif)$/,
loaders: 'file-loader',
}, {
test: /\.html$/,
loader: 'html-loader',
}, {
test: /\.json$/,
loader: 'json-loader',
}, {
test: /\.(mp4|webm)$/,
loader: 'url-loader?limit=10000',
},
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{test: /\.tsx?$/, loader: "awesome-typescript-loader"},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{enforce: "pre", test: /\.js$/, loader: "source-map-loader"}
],
},
plugins: options.plugins.concat([
new webpack.ProvidePlugin({
// make fetch available
fetch: 'exports?self.fetch!whatwg-fetch',
'$': 'jquery',
'jQuery': 'jquery'
}),
// Always expose NODE_ENV to webpack, in order to use `process.env.NODE_ENV`
// inside your code for any environment checks; UglifyJS will automatically
// drop any unreachable code.
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
]),
resolve: {
// modulesDirectories: ['app','node_modules'],
modules: ['node_modules', 'app'],
extensions: [
'.js',
'.ts',
'.jsx',
'.tsx',
'.react.js',
],
mainFields: [
'jsnext:main',
'main',
],
},
devtool: options.devtool,
target: 'web', // Make web variables accessible to webpack, e.g. window
stats: false, // Don't show stats in the console
});
"babel": {
"presets": [
[
"latest",
{
"es2015": {
"modules": false
}
}
],
"react",
"stage-0"
],
"env": {
"production": {
"only": [
"app"
],
"plugins": [
"transform-react-remove-prop-types",
"transform-react-constant-elements",
"transform-react-inline-elements"
]
},
"test": {
"plugins": [
"istanbul"
]
}
}
}