我有以下功能:
export default function(path, urlKey = 'static') {
if (urlKey === 'static') {
path = require(`~/static${path}`).default;
}
urlKey = Object.keys(config.app.urls).includes(urlKey) ? urlKey : 'static';
return (config.app.urls[urlKey] + '/' + path).replace(/([^:]\/)\/+/g, "$1");
};
如您所见,我正在使用require
我认为利用require.context
. 当我的 webpack 打包时,它会构建静态文件夹中的所有文件。~/static
路径的一部分是static
根目录中我的文件夹的别名。
使用watch
webpack 的模式时,打包进入死循环。
我尝试了各种方法,例如watchOptions.ignored
和 ,WatchIgnorePlugin
但这些都没有奏效。
这是我对上述解决方案的两次尝试:
watchOptions: {
ignored: /static/
}
和
plugins:[
new WatchIgnorePlugin([
path.resolve(__dirname, '..', 'static')
]),
]
谁能建议我在这里缺少什么?