- Progressive Web Apps with React
- Scott Domes
- 194字
- 2021-07-08 09:36:20
Creating a custom script
Make a new folder in the root of your directory and name it scripts. Inside, make a file called copy_assets.js.
In here, we will copy everything in public to build, excluding our index.html.
To do this (you guessed it), we need one more package; run yarn add fs-extra.
Then, require it inside copy_assets.js, as illustrated:
var fs = require('fs-extra');
fs-extra is a package used for manipulating files in a Node environment. It has a method called copySync, which we'll use here.
The code is rather straightforward:
fs.copySync('public', 'build', {
dereference: true,
filter: file => file !== 'public/index.html'
});
This says copy everything in the public folder to the build folder, except the index.html file.
Now, to run this command whenever we build, add it to the build script in package.json:
"scripts": {
"build": "node scripts/copy_assets.js && node_modules/.bin/webpack --config
webpack.config.prod.js",
"start": "node_modules/.bin/webpack-dev-server"
},
It's a good idea to put the copy_assets command before our Webpack command, just to ensure that we don't accidentally copy any JavaScript assets in public without transpiling them.
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- 程序員面試筆試寶典(第3版)
- 深度實踐OpenStack:基于Python的OpenStack組件開發(fā)
- JavaScript修煉之道
- Learning Docker
- JavaScript 網(wǎng)頁編程從入門到精通 (清華社"視頻大講堂"大系·網(wǎng)絡開發(fā)視頻大講堂)
- Spring Boot+Spring Cloud+Vue+Element項目實戰(zhàn):手把手教你開發(fā)權限管理系統(tǒng)
- C語言最佳實踐
- Python編程完全入門教程
- 編譯系統(tǒng)透視:圖解編譯原理
- PLC編程及應用實戰(zhàn)
- Mastering Apache Spark 2.x(Second Edition)
- Getting Started with Laravel 4
- Windows Phone 7.5:Building Location-aware Applications
- Mastering Git