从webpack输出中删除absulte路径

时间:2018-05-02 10:42:26

标签: reactjs webpack absolute-path

好吧,我在生产模式下使用webpack构建我的应用程序,我的输出文件包含绝对路径,如:

E:/xxxx/xxxx/src/app/core/components/lib/RadioButtonGroupEntry.js

这是我的webpack配置:

resolve: {
    //When require, do not have to add these extensions to file's name
    extensions: ["", ".js", ".jsx"],
},
//Render source-map file for final build

//output config
output: {
    path: buildPath,    //Path of output file
    filename: '[name]-[chunkhash].js', //Name of output file
    publicPath: '/'
},

node: {
    fs: 'empty'
},
plugins: [
    //Minify the bundle
    new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production')
    }),
    new webpack.optimize.UglifyJsPlugin({
        compress: {
            //supresses warnings, usually from module minification
            warnings: false
        }
    }),
    //Allows error warnings but does not stop compiling. Will remove when eslint is added
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.CommonsChunkPlugin({
        name: "vendor",
        minChunks: Infinity,
    }),

    // new InlineManifestWebpackPlugin({
    //     name: 'webpackManifest'
    // }),
    new WebpackMd5Hash(),
    // new ManifestPlugin(),
    // new ChunkManifestPlugin({
    //     filename: "chunk-manifest.json",
    //     manifestVariable: "webpackManifest"
    // }),
    new HtmlWebpackPlugin({template: 'src/www/index.ejs'}),
    //Transfer Files
    new TransferWebpackPlugin([{from: 'www'}], path.resolve(__dirname,'src'))]

我认为我的webpack.config搞砸了,我想帮助找出它的错误,以便删除绝对路径。 感谢。

2 个答案:

答案 0 :(得分:0)

也许您可以尝试使用路径和节点__dirname全局对象来配置webpack配置对象的输出路径属性,如下所示:

output: {
  path: path.resolve(__dirname, 'yourBuildFolder')
}

答案 1 :(得分:0)

我遇到了类似的问题(我使用了多个条目),并用path.relative()解决了这个问题:

{
  entry: {
    'head': [
      `./${path.relative(__dirname, 'my/source/path.js')}`,
      ...
    ]
  },
  ...
}