10、webpack开发--自动编译源代码
如果我们更改了源代码,而不像每次都要运行npm run build,该如何办呢?1、更改package.json文件,scripts追加"watch": "webpack --watch"开启webpack watch模式{"name": "webpack-demo","version": "1.0.0","description": "","private": ...
·
如果我们更改了源代码,而不像每次都要运行npm run build,该如何办呢?
1、更改package.json文件,scripts追加"watch": "webpack --watch"开启webpack watch模式
{
"name": "webpack-demo",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"watch": "webpack --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"clean-webpack-plugin": "^2.0.2",
"css-loader": "^2.1.1",
"csv-loader": "^3.0.2",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"style-loader": "^0.23.1",
"webpack": "^4.32.0",
"webpack-cli": "^3.3.2",
"xml-loader": "^1.2.1"
},
"dependencies": {
"lodash": "^4.17.11"
}
}
2、watch模式运行
npm run watch
3、运行效果
4、修改print.js文件
export default function print() {
// console.error('code find a error!'); 修改前
console.log('code was updated!');
}
5、刷新页面,运行效果如下:
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献3条内容
所有评论(0)