我正在尝试使用copy-webpack-plugin将我的app / images目录中的文件复制到public/img
npm run development
。但由于某种原因,我收到以下错误:
npm ERR! Darwin 13.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "webpack-dev-server"
npm ERR! node v5.8.0
npm ERR! npm v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! global-gamesey@1.0.0 webpack-dev-server: `NODE_ENV=development PORT=8080 webpack-dev-server --content-base public/ --hot --inline --devtool inline-source-map --history-api-fallback`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the global-gamesey@1.0.0 webpack-dev-server script 'NODE_ENV=development PORT=8080 webpack-dev-server --content-base public/ --hot --inline --devtool inline-source-map --history-api-fallback'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the global-gamesey package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! NODE_ENV=development PORT=8080 webpack-dev-server --content-base public/ --hot --inline --devtool inline-source-map --history-api-fallback
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs global-gamesey
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls global-gamesey
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/travis.tb/git/global-gamesey/npm-debug.log
npm ERR! Darwin 13.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "development"
npm ERR! node v5.8.0
npm ERR! npm v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! global-gamesey@1.0.0 development: `cp views/index.html public/index.html && NODE_ENV=development webpack && npm run webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the global-gamesey@1.0.0 development script 'cp views/index.html public/index.html && NODE_ENV=development webpack && npm run webpack-dev-server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the global-gamesey package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! cp views/index.html public/index.html && NODE_ENV=development webpack && npm run webpack-dev-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs global-gamesey
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls global-gamesey
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/travis.tb/git/global-gamesey/npm-debug.log
为什么我的脚本失败了?在我的webpack.config文件中,我包含以下几行:
// webpack.config.js
var webpack = require('webpack')
//copy files
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
if(process.env.NODE_ENV === 'development'){
var loaders = ['react-hot','babel']
} else {
var loaders = ['babel']
}
module.exports = {
devtool: 'eval',
entry: './app-client.js',
output: {
path: __dirname + '/public/dist',
filename: 'bundle.js',
publicPath: '/dist/'
},
module: {
loaders: [{
test: /\.js$/,
loaders: loaders,
exclude: /node_modules/
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}
]},
plugins: [
new webpack.DefinePlugin({
'process.env.COSMIC_BUCKET': JSON.stringify(process.env.COSMIC_BUCKET)
}),
new CopyWebpackPlugin([
{ from: '/images/', to: '/public/img/' }
])
]
};
我做错了吗?我来自Gulp的观点,所以我发现webpack处理这个简单任务的方式真的很奇怪。
答案 0 :(得分:1)
CopyWebpackPlugin文档指出您必须将以下条目添加到“webpack.config.js”配置文件中。
`
...
devServer: {
// This is required for webpack-dev-server. The path should
// be an absolute path to your build destination.
outputPath: path.join(__dirname, 'build')
},
...`