1. Webpack can’t statically analyze what’s inside eval. So it won’t bundle the faker module.
[cc lang=”js”]const faker = eval(“require(‘faker’)”)[/cc]
2. Create a file called next.config.js in your Next.js app and add the webpack IgnorePlugin.
[cc lang=”js”]module.exports = {
webpack: function (config) {
config.plugins.push(
new require(‘webpack’).IgnorePlugin(/faker/)
)
return config
}
}[/cc]
3. USING THE “BROWSER” FIELD OF THE “PACKAGE.JSON”
You can also ask webpack to disable bundling faker module via adding a config in the main package.json file.
Add the following code in to your package.json file.
[cc lang=”js”]{
…
“browser”: {
“faker”: false
}
…
}[/cc]
One Reply to “next.js 或 PWAs 只在服务需要运行的模块,但会打包到 client 里”