我正在尝试扩展项目以进行生产,并且很难将所有静态文件复制到构建文件夹中。当我运行npm脚本时,它会将所有内容复制到我的build文件夹中,但是在复制时,它会带来整个public
目录。我只想复制公共目录中的所有内容并将其复制到我的build文件夹中进行生产。但是,我不确定我的npm脚本在做什么。
这是我的代码:
{
"scripts": {
"client": "webpack-dev-server --progress --color --profile --config webpack.development.config.js --mode development --hot",
"clean": "rm -rf build public/bundle.js && rm -rf build public/bundle.js.gz",
"server": "nodemon server/main.js",
"sass": "node-sass -w public/assets/scss -o public/assets/css/ --recursive",
"dev": "concurrently \"npm run server\" \"npm run sass\" \"npm run client\"",
"prod": "npm run clean && webpack --config webpack.production.config.js --mode production --progress --colors --profile",
"prod:cp": "cp ./package.json build/ && cp ./dbconnection.js build/ && cp ./webpack.development.config.js build/ && cp -R ./services build/ && cp -R ./routes build/ && cp -R ./public build/ && cp -R ./models build/"
}
}
我运行“ prod:cp” npm命令后的屏幕截图:
答案 0 :(得分:0)
需要将cp -R ./public build/
更改为cp -R ./public/. build/
{
"scripts": {
"client": "webpack-dev-server --progress --color --profile --config webpack.development.config.js --mode development --hot",
"clean": "rm -rf build public/bundle.js && rm -rf build public/bundle.js.gz",
"server": "nodemon server/main.js",
"sass": "node-sass -w public/assets/scss -o public/assets/css/ --recursive",
"dev": "concurrently \"npm run server\" \"npm run sass\" \"npm run client\"",
"prod": "npm run clean && webpack --config webpack.production.config.js --mode production --progress --colors --profile",
"prod:cp": "cp ./package.json build/ && cp ./dbconnection.js build/ && cp ./webpack.development.config.js build/ && cp -R ./services build/ && cp -R ./routes build/ && cp -R ./public/. build/ && cp -R ./models build/"
}
}