I produced a small code for building by webpack. The source entry file is like:
import archiver from 'archiver'
import request from 'request'
import mkdirp from 'mkdirp'
import Zip from 'node-zip'
import Zlib from 'zlib'
import path from 'path'
import fs from 'fs'
export default class myTestClass {
constructor (config) {
super (config)
}
//......
}
The webpack config is:
var webpack = require('webpack');
var path = require('path')
module.exports = {
entry: [
path.resolve("./js/app.js")
],
output: {
path: path.resolve('./build'),
filename: "build.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.scss$/, loader: 'style!css!sass?sourceMap'},
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015'],
plugins: ['transform-runtime']
}
}
]
},
resolve: {
modules: [
"./js",
"./node_modules"
],
extensions : ['.js', '.jsx', '.json']
},
resolveLoader: {
modules: ['node_modules']
},
node: {
console: true
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.ProvidePlugin({
'window.jQuery': 'jquery',
Promise: 'bluebird',
jQuery: 'jquery',
$: 'jquery'
})
]
};
The main app.js simply calls myTestClass:
import MyClass from './myTestClass.js'
module.exports = async function() {
const myCls = new MyClass();
return '';
};
Running webpack, I got many same errors:
Module not found: Error: Can't resolve 'fs'
If I followed the comment in https://github.com/webpack-contrib/css-loader/issues/447 , i.e.
node:{
fs:'empty'
}
It can be built, but when running the code on client, an error will pop out from the build.js. The error is: fs is undefined. I think this is because fs of node is set to empty.
var fs$ReadStream = fs.ReadStream
ReadStream.prototype = Object.create(fs$ReadStream.prototype)
ReadStream.prototype.open = ReadStream$open
Could you shed a light how to solve this issue? is that a correct usage to set fs = empty? IF it is correct, what issue with the build.js?