1
我无法将nodejs的核心模块加载到浏览器。如何使用webpack加载Nodejs核心模块
我xlsx
库取决于fs
这是一个核心模块,并加载我的应用程序产生cannot find module "fs"
错误。
我做了一些谷歌上搜索一再结束了here - 说我要补充target:node
我webpack.config.js
文件,但是,做了他认为会产生另一个错误 - >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'
};
任何见解将大大apreciated,在此先感谢,并请让我知道如果任何其他信息将是有益的。
我不使用babel
也不gulp
我明白了,这很有道理。那么我应该怎么做''使用'fs'来使用'xlsx'? –
这取决于图书馆。你可以在没有'fs'的情况下使用它吗?通过来自服务器的HTTP请求手动加载文件?那就这样做。否则,你将不得不寻找一个不同的库。 – Timo
这可能超出了问题的范围,但更确切地说,我使用'ng2-file-uploader'从客户端获取文件并使用'node-xlsx'将文件解析为对象,所有这些在没有使用服务器的客户端上,有什么建议? –