Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 有没有办法获得网页链接的绝对路径?_Webpack_Path_Absolute Path - Fatal编程技术网

Webpack 有没有办法获得网页链接的绝对路径?

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

我有这样一个网页配置

我已经建立了一个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(__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/
)。我们期待在这里发生什么?是的,你可能是对的-网页与此无关。我找错地方了。