如何解决rollup.js_Bundle自动更新
我正在尝试通过VSCode中的rollup.js进行捆绑。
My directory:
----MyProject
--------\node_modules
-----------\.bin
-----------\rollup
--------index.js
--------index.html
--------bundle.js
--------package-lock.json
--------package.json
在我的.html
文件中,我与bundle.js
有关联,我在index.js
中所做的所有更改都必须在bundle.js中自动更新。但这仅在我在终端中运行以下命令时有效:rollup index.js --file bundle.js
我的package.json
:
{
"name": "npm","version": "1.0.0","description": "","main": "index.js","scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},"author": "","license": "ISC","dependencies": {
"rollup": "^2.34.2"
}
}
要使该系统自动运行我需要做什么?
解决方法
首先,我没有配置文件,所以我创建了rollup.config.js
:
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
const watch = process.env.ROLLUP_WATCH
export default {
input: 'src/index.js',output: {
file: 'dist/bundle.js',format: 'iife'
},plugins: [
watch && serve('dist'),watch && livereload()
]
}
然后我将这两个脚本添加到package.json
中:
"build": "rollup -c","dev": "rollup -c -w"
并在终端npm run dev
我对vladshcherbin的帮助表示感谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。