当我运行命令webpack -p时,我得到了errno 2.
当我只运行webpack时,一切正常。
所以我在package.json上有以下命令:
"dev": "rimraf dist && NODE_ENV=development webpack",
"build": "rimraf dist && NODE_ENV=production webpack -p",
为我的webpack.config.js配置此配置:
const path = require('path');
const webpack = require('webpack');
const SassLintPlugin = require('sasslint-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const extractSass = new ExtractTextPlugin({
filename: '[name].css',
disable: process.env.NODE_ENV === 'development',
});
const plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
STAGE: JSON.stringify(process.env.STAGE),
},
}),
new CopyWebpackPlugin([
{ from: path.join(__dirname, 'app/js/pwa/manifest.json'), to: path.join(__dirname, 'dist') },
{ from: path.join(__dirname, 'app/js/pwa/sw.js'), to: path.join(__dirname, 'dist') },
{ from: path.join(__dirname, 'app/js/pushstream/pushstream.js'), to: path.join(__dirname, 'dist') },
{ from: path.join(__dirname, 'app/img/favicon.png'), to: path.join(__dirname, 'dist') },
{ from: path.join(__dirname, 'app/img/tecnoseniorIcon.png'), to: path.join(__dirname, 'dist') },
]),
new SassLintPlugin({
configFile: '.sass-lint.yml',
context: [path.resolve(__dirname, './app/')],
ignoreFiles: [],
ignorePlugins: [],
glob: '**/*.s?(a|c)ss',
quiet: false,
failOnWarning: false,
failOnError: true,
testing: false,
}),
extractSass,
new HtmlWebpackPlugin({
title: 'Contactto Anywhere',
template: 'app/index-template.html',
// minify: {
// collapseWhitespace: process.env.NODE_ENV === 'production',
// },
}),
];
if (process.env.NODE_ENV === 'development') {
plugins.push(new webpack.HotModuleReplacementPlugin());
}
if (process.env.NODE_ENV === 'production') {
plugins.push(new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}));
plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
}
module.exports = {
entry: process.env.NODE_ENV === 'development' ?
{
main: [
'webpack-hot-middleware/client?reload=true',
'react-hot-loader/patch',
'./app/index.jsx',
],
pwa: './app/js/pwa/mainPwa.js',
}
:
{
main: './app/index.jsx',
pwa: './app/js/pwa/mainPwa.js',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
target: 'web',
devtool: process.env.NODE_ENV === 'development' ? 'inline-source-map' : 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
include: path.resolve(__dirname, './app/'),
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
include: path.resolve(__dirname, './app/'),
loader: extractSass.extract({
use: [
{ loader: 'css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]' },
{ loader: 'sass-loader' },
],
// use style-loader in development
fallback: 'style-loader',
}),
exclude: /node_modules/,
},
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'file-loader?name=fonts/[name].[ext]',
},
{
test: /\.(png|svg|jpg|webp)$/,
use: {
loader: 'file-loader',
},
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
modules: [path.resolve(__dirname, 'node_modules')],
},
plugins,
};
webpack -p几天前正在运行,但现在却出现了这个错误。 我很长时间没有改变我的webpack.config.js。
日志文件:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@5.3.0
3 info using node@v8.0.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle contactto-master@1.0.0~prebuild: contactto-master@1.0.0
6 info lifecycle contactto-master@1.0.0~build: contactto-master@1.0.0
7 verbose lifecycle contactto-master@1.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle contactto-master@1.0.0~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/alexfqc/Documents/contactto-master-frontend/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/alexfqc/Library/Android/sdk/tools:/Users/alexfqc/Library/Android/sdk/platform-tools:/Users/alexfqc/mongodb-osx-x86_64-enterprise-3.4.6/bin
9 verbose lifecycle contactto-master@1.0.0~build: CWD: /Users/alexfqc/Documents/contactto-master-frontend
10 silly lifecycle contactto-master@1.0.0~build: Args: [ '-c', 'rimraf dist && NODE_ENV=production webpack -p' ]
11 silly lifecycle contactto-master@1.0.0~build: Returned: code: 2 signal: null
12 info lifecycle contactto-master@1.0.0~build: Failed to exec build script
13 verbose stack Error: contactto-master@1.0.0 build: `rimraf dist && NODE_ENV=production webpack -p`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
13 verbose stack at emitTwo (events.js:125:13)
13 verbose stack at EventEmitter.emit (events.js:213:7)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
13 verbose stack at emitTwo (events.js:125:13)
13 verbose stack at ChildProcess.emit (events.js:213:7)
13 verbose stack at maybeClose (internal/child_process.js:887:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
14 verbose pkgid contactto-master@1.0.0
15 verbose cwd /Users/alexfqc/Documents/contactto-master-frontend
16 verbose Darwin 16.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v8.0.0
19 verbose npm v5.3.0
20 error code ELIFECYCLE
21 error errno 2
22 error contactto-master@1.0.0 build: `rimraf dist && NODE_ENV=production webpack -p`
22 error Exit status 2
23 error Failed at the contactto-master@1.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
我不知道发生了什么,有人可以帮助我吗?
提前致谢。
答案 0 :(得分:0)
我发现了错误,
我试图使用async并等待没有预设。