我是否应该进行一些特定的配置以使Webpack进入polyfill path
?感觉这应该很简单,但我根本无法使它正常工作。我所有在前端使用path.parse
的尝试都以TypeError: path.parse is not a function
的某种变体结束。
请参阅下面的完整Webpack配置,这是Webpack 4.20.1和节点8.12.0的内容。
webpack doc建议path
默认情况下应进行多填充,但由于某些原因,它不是。
我尝试在配置中强制将target
强制为"web"
,将node
强制为{path: true}
,但是结果是相同的。
我只能以为我做的事情显然很错,以至于看不到它。
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require("path");
const config = {
devServer: {
hot: true,
port: 4500
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
entry: {
app: ["babel-polyfill", "./client/index.tsx"]
},
mode: "empty",
output: {
chunkFilename: "[name].[chunkhash].js",
filename: "[name].bundle.[chunkhash].js",
path: path.resolve(__dirname, "../dist"),
publicPath: ""
},
optimization: {
splitChunks: {
chunks: "all"
}
},
plugins: [
new CleanWebpackPlugin([path.resolve(__dirname, "../dist")], {
root: path.resolve(__dirname, ".."),
verbose: true
}),
// generate a single html file bundling everything produced by webpack
new HtmlWebPackPlugin({
// favicon: "./src/favicon.ico",
filename: "./index.html",
template: "./client/index.html"
}),
new CompressionPlugin()
],
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
loader: "awesome-typescript-loader",
test: /\.tsx?$/
},
// All output '.js', '.jsx', '.ts' or '.tsx' files will have any sourcemaps pre-processed by 'source-map-loader'.
{
enforce: "pre",
// exclude modules that cause warnings
exclude: [
// https://github.com/apollographql/apollo-client/issues/3699
/node_modules[/\\]apollo-client/
],
test: /\.[jt]sx?$/,
use: ["source-map-loader"]
},
// All graphql files. Allows the client to import it into the code.
{
exclude: /node_modules/,
loader: "graphql-tag/loader",
test: /\.(graphql|gql)$/
}
]
}
};
module.exports = config;