我正在使用 Rollup.js 构建一个 React 应用程序,并尝试使用实时重新加载来获得更好的 DX。
我安装了所有软件包,第一次运行时一切看起来都很好。
当我尝试更新我的源代码时,会重新构建包并刷新页面,但更改不会出现在已编译的 JS 中。如果我结束进程并重新启动,更改就会出现。
rollup.config.ts 附在下面:
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import url from './renderer/rollupImageAssetsUrl';
import rollupUrl from '@rollup/plugin-url';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import dts from 'rollup-plugin-dts';
import svgr from '@svgr/rollup';
import type { RollupOptions } from 'rollup'
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
const devConfig : RollupOptions = {
input: './template/index.tsx',
output: {
file: './template/build/index.js',
format: 'iife'
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify( 'production' ),
CLASS_TYPE : process.env.CLASS_TYPE ? JSON.stringify(process.env.CLASS_TYPE) : JSON.stringify(`oocss`)
}),
resolve({
browser: true,
dedupe: ['react', 'react-dom'],
}),
typescript({
tsconfig: './renderer/tsconfig.json',
declaration: false,
paths : {
"component-library/style-library" : ["./../src/index.ts"]
}
}),
commonjs(),
url({
fileName: 'images/[name][extname]',
exclude: ['**/src/Icons/**/**.svg'],
limit: 0,
preserveImports: true
}),
rollupUrl({
include: ['**/src/Icons/**/**.svg']
}),
svgr({
icon: true,
replaceAttrValues : {
"#000" : "currentColor",
"black" : "currentColor",
"#000000" : "currentColor"
},
svgProps: {
'pointerEvents' : 'none',
}
}),
serve({
contentBase: './template',
host: '0.0.0.0',
port: '3002',
}),
livereload({
port: 3003,
delay: 200
}),
],
watch: {
buildDelay: 500,
clearScreen: true
}
}
export default devConfig;
附上我的 Docker 设置:
version: '3.9'
services:
builder:
container_name: style_library_package_builder_dev
build:
context: .
dockerfile: docker_images/builder/Dockerfile
image: style-library-package-builder:v0.2.0
ports:
- "3002:3002"
- "3003:3003"
environment:
- "TZ=Asia/Tokyo"
- "CHOKIDAR_USEPOLLING=true"
- "WATCHPACK_POLLING=true"
volumes:
- ./app/.storybook:/var/app/builder/.storybook
- ./app/renderer:/var/app/builder/renderer
- ./app/utils:/var/app/builder/utils
- ./app/template:/var/app/builder/template
- ./app/package.json:/var/app/builder/package.json
- ./app/rollup.config.ts:/var/app/builder/rollup.config.ts
- ./app/rollup.config.dev.ts:/var/app/builder/rollup.config.dev.ts
- ./app/tsconfig.json:/var/app/builder/tsconfig.json
- ./app/webpack.config.style.ts:/var/app/builder/webpack.config.style.ts
- ./app/yarn.lock:/var/app/builder/yarn.lock
- ./app/.babelrc.json:/var/app/builder/.babelrc.json
- ./component-library/style-library/builder/src:/var/app/builder/src
- ./component-library/style-library/builder/assets:/var/app/builder/assets
- ./component-library/style-library/builder/stories:/var/app/builder/stories
- ./component-library/style-library/builder/config:/var/app/builder/config
- ./component-library/style-library/lib:/var/app/lib
- ./component-library/style-library/package.json:/var/app/package.json
- ./component-library/package.json:/var/package.json
- ./component-library/docs:/var/docs
- /var/app/builder/node_modules
tty: true
privileged: true
secrets:
- host_ssh_key
secrets:
host_ssh_key:
file: ${KEY}
我在 Docker 容器中运行 rollup.js(带有图像节点:18-alpine3.15)。
您是否可以想到有关此行为的任何原因?
任何帮助表示赞赏。
试过
CHOKIDAR_USEPOLLING=true
和rollup.watch.chokidar.usePolling = true
但没有运气