- 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.
- Cocos2D-X權(quán)威指南(第2版)
- Hands-On Data Structures and Algorithms with JavaScript
- PostgreSQL Replication(Second Edition)
- Windows Forensics Cookbook
- Android應(yīng)用案例開發(fā)大全(第二版)
- Learning PHP 7
- Oracle GoldenGate 12c Implementer's Guide
- Hands-On Robotics Programming with C++
- 嵌入式Linux C語言程序設(shè)計基礎(chǔ)教程
- Mastering Android Studio 3
- INSTANT JQuery Flot Visual Data Analysis
- 實驗編程:PsychoPy從入門到精通
- Raspberry Pi開發(fā)實戰(zhàn)
- Unity虛擬現(xiàn)實開發(fā)圣典
- jBPM6 Developer Guide