使用http-server
npm install http-server -D
"scripts": {
"server": "http-server build",
"start": "webpack-dev-server --config ./config/webpack.common.js",
"build": "webpack --env.production=abc --config ./config/webpack.common.js"
}
console.log('Hello Dingding')
npm build
npm run server
PWA
npm install workbox-webpack-plugin -D
- PWA用于生产包,因此修改webpack.prod.js
plugins:[
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].chunk.css'
}),
// 使用WorkBox插件
new WorkBoxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true
})
]
console.log('Hello Dingding')
if('serviceWorker' in navigator) {
window.addEventListener('load',() => {
navigator.serviceWorker.register('./service-worker.js')
.then(register => {
console.log('success')
})
.catch(e => console.log(e))
})
}
网友评论