Webpack 有没有办法获得网页链接的绝对路径?
我有这样一个网页配置 我已经建立了一个publicPath:“/”-但它似乎不起作用 我使用过“webpack”:“^3.12.0”和“webpack dev server”:“^2.11.2”,如果这很重要的话Webpack 有没有办法获得网页链接的绝对路径?,webpack,path,absolute-path,Webpack,Path,Absolute Path,我有这样一个网页配置 我已经建立了一个publicPath:“/”-但它似乎不起作用 我使用过“webpack”:“^3.12.0”和“webpack dev server”:“^2.11.2”,如果这很重要的话 module.exports = { entry: ["./src/index.js", "./src/styles/main.scss"], output: { filename: "bundle.js", path: path.resolve(__dir
module.exports = {
entry: ["./src/index.js", "./src/styles/main.scss"],
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "./public/dist"),
publicPath: '/'
},
module: {
rules: [
{
test: /\.scss/,
loader: ExtractTextPlugin.extract(["css-loader", "sass-loader"])
},
{
test: /\.js$/,
exclude: /node_modules/,
loaders: "babel-loader",
options: {
presets: ["react", "stage-0", "es2015"],
plugins: ["transform-class-properties"]
}
}
]
},
devServer: {
contentBase: "./public/",
watchContentBase: true,
port: 3000
},
plugins: [
new ExtractTextPlugin("bundle.css"),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
}),
new webpack.optimize.UglifyJsPlugin()
]
};
但是我在标签a中的链接:
<a href="/">Text</a>
仍然导致localhost:3000
有没有办法获取链接的绝对路径?tag href属性与webpack无关。每当我们在href中给出
/
时,它总是指向基础url,即本地的localhost:3000/
,如果它部署在某个地方,它将是服务器url(比如,mydomain.com/
)。我们期待在这里发生什么?是的,你可能是对的-网页与此无关。我找错地方了。