当我尝试为我的Node服务器构建应用程序时,我不断收到描述中的错误。
我最终想要读取一个.docx文件以供docxtemplater使用,但是由于'fs'无法正常工作,这看起来并不太好。
我已经尝试使用node:{fs:"empty"}解决方法,在许多解决方案中都看到过,但在运行它时仍然会给我相同的错误或向控制台传播。
这是我在webpack.config.js中的内容:
var path = require('path');
var webpack = require('webpack');
//var HtmlWebpackPlugin = require('html-webpack-plugin');
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var DashboardPlugin = require('webpack-dashboard/plugin');
const sourcePath = path.join(__dirname, './front_end');
const buildPath = path.join(__dirname, './src/bin');
module.exports = {
devtool: 'source-map',
//home directory for webpack must be absolute
//context: sourcePath,
//Application Execution and Webpack Bundling
entry: {
js: path.join(sourcePath, 'index.js')
//html: './index.html',
},
output: {
//Must be absolute path
path: sourcePath,
//publicPath: buildPath,
//publicPath: path.join(__dirname, '/src/bin'),
filename: "bundle.js"
},
resolve: {
extensions: [
'.webpack-loader.js',
'.web-loader.js',
'.loader.js',
'.js',
'.jsx'
],
modules: [
path.join(__dirname),
"node_modules"
],
},
module: {
rules: [
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
use: [
"babel-loader",
"eslint-loader",
]
},
{
test: /\.html/,
exclude: /node_modules/,
use: [
"file-loader",
]
},
{
test: /\.css/,
exclude: /node_modules/,
use: [
"style-loader",
'css-loader'
]
},
{
test: /\.(gif|png)/,
exclude: /node_modules/,
use: [
"url-loader"
]
}
],
loaders: [
{
test: /\.js$|\.jsx$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2016', 'react']
}
},
{
test: /\.css$/,
loader: 'style-loader',
use: ['style-loader', 'css-loader'],
exclude: /node_modules/
},
{
test: /\.html$/,
loader: "file?name=[name].[ext]"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
plugins: [
],
stats: {
assets: true,
colors: true,
errors: true,
errorDetails: true,
hash: true,
}
};
<img>
和<link>
等加载资源的能力,或者使用特殊的加载程序将它们捆绑在一起。 - Mike 'Pomax' Kamermans