when I was packing with webpack, I first reported an error
"ERROR in build.js from UglifyJs
Unexpected token: punc ((). / node_modules/element-ui/packages/col/src/col.js:24,0"
according to the search result was es6 grammar problem
and then I changed webpack to this
"
var path = require ("path")
var webpack = require (" webpack")
const UglifyJsPlugin = require ("uglifyjs-webpack-plugin");
module.exports = {
entry:". / src/main.js",
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/dist/",
filename: "build.js"
},
module: {
rules: [
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
use: [
"vue-style-loader",
"css-loader",
"sass-loader"
],
},
{
test: /\.sass$/,
use: [
"vue-style-loader",
"css-loader",
"sass-loader?indentedSytanx"
],
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: "file-loader"
},
{
test: /\.vue$/,
loader: "vue-loader",
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
"scss": [
"vue-style-loader",
"css-loader",
"sass-loader"
],
"sass": [
"vue-style-loader",
"css-loader",
"sass-loader?indentedSyntax"
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: "babel-loader",
include: [resolve("src"),resolve("test"), resolve("/node_modules/iview/src"), resolve("/node_modules/iview/packages")],
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: "file-loader",
options: {
name: "[name].[ext]?[hash]"
}
}
]
},
resolve: {
alias: {
"vue$": "vue/dist/vue.esm.js"
},
extensions: ["*", ".js", ".vue", ".json"]
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true,
host: "0.0.0.0"
},
performance: {
hints: false
},
devtool:"- sharpeval-source-map"
}
if (process.env.NODE_ENV = "production") {
module.exports.devtool ="-sharpsource-map"
/ /
module.exports.plugins = (module.exports.plugins | | []). Concat ([
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: ""production""
}
}),
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true,
// compress: {
// warnings: false
// }
// }),
new UglifyJsPlugin({
// js
parallel: true,
uglifyOptions: {
ie8: false,
ecma: 6,
warnings: false,
mangle: true,
// debug false
output: {
comments: false,
beautify: false,
// debug true
},
compress: {
// UglifyJs
warnings: false,
// `console`
// ie
drop_console:
true,
//
collapse_vars:
true,
//
reduce_vars:
true,
}
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
"
run npm run build, again and report an error
"
path: path.resolve (_ _ dirname,". / dist"),
^
ReferenceError: resolve is not defined
at Object.<anonymous> (C:\Users\yingyi\Desktop\yingyi\webpack.config.js:8:16)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at requireConfig (C:\Users\yingyi\Desktop\yingyi\node_modules\webpack\bin\convert-argv.js:97:18)
at C:\Users\yingyi\Desktop\yingyi\node_modules\webpack\bin\convert-argv.js:104:17
npm err! Code ELIFECYCLE
npm err! Errno 1
npm err! Yingyi@1.0.0 build: cross-env NODE_ENV=production webpack-- progress-- hide-modules
npm err! Exit status 1
npm err!
npm err! Failed at the yingyi@1.0.0 build script.
npm err! This is probably not a problem with npm. There is likely additional logging output above.
npm err! A complete log of this run can be found in:
npm err! C:UsersyingyiAppDataRoamingnpm-cache_logs2018-05-21T11_19_19_460Z-debug.log
"
what is the reason for this