如何使用webpack加载Nodejs核心模块

我无法将nodejs的核心模块加载到浏览器。

我的xlsx库取决于fs这是一个核心模块,并加载我的应用程序产生cannot find module "fs"错误。

我已经做了一些谷歌search一再结束在这里 – 说我应该添加target:node到我的webpack.config.js文件,但是,完成,因为他build议产生另一个错误 – > process is not defined

我想知道是否有任何模块加载器需要? 我找不到任何。

webpack.config.js

 module.exports = { entry: "./app/boot", output: { path: __dirname, filename: "./dist/bundle.js" }, resolve: { extensions: ['', '.js', '.ts'] }, module: { loaders: [ { test: /\.ts/, loaders: ["ts-loader"], exclude: /node_modules/ } ], preLoaders: [ // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. { test: /\.js$/, loader: "source-map-loader", exclude: ['node_modules', 'ext-*', 'lib', 'tools'] } ] }, debug: true, devtool: 'source-map' }; 

任何见解都会被大大降低,请提前感谢,如果有任何其他信息会有所帮助,请告诉我们。

我不使用babel也不使用babel

你不能。

在浏览器中没有可以正常工作的fs 。 在浏览器中执行的JavaScript出于安全原因正在沙箱中运行,并且您对客户端文件系统的访问权限非常有限, 这是在NodeJS中使用的模块fs