shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.44k stars 184 forks source link

Add support for absolute paths in outputs #87

Closed ivancuric closed 6 years ago

ivancuric commented 6 years ago

I have a use case where I'd like to output the manifest.json in a different folder than where the bundles are output.

However, if I want to output it in the parent directory, I have to use fileName: '../manifest.json'.

This is not really maintainable cross-config.

mastilver commented 6 years ago

33 duplicate

Use an absolute path

ivancuric commented 6 years ago

Not working. If using an absolute path like fileName: path.join(__dirname, 'dist','manifest.json'), it just gets appended to the output directory, eg: ./dist/Users/ivan/Dev/projectName/dist/manifest.json

mastilver commented 6 years ago

Weird... We have one test that cover that: https://github.com/danethurber/webpack-manifest-plugin/blob/78c53210716e9c32c9b1d840ab5ce11b4750bbe1/spec/plugin.spec.js#L500-L522

Do you mind sending us a failing test so we can have a better look

ivancuric commented 6 years ago

Uh, never done tests before, but I can send you a reduced config:

./webpack.config.js ```js const ManifestPlugin = require('webpack-manifest-plugin'); const paths = require('./_scripts/paths'); const manifestPath = paths.dist.root + 'manifest.json'; const basePlugins = () => [ new ManifestPlugin({ fileName: manifestPath, cache: JSON.parse(fs.readFileSync(manifestPath, 'utf8')), }), ]; const config = { entry: { entry: paths.src.js + 'entry.js', }, output: { path: paths.dist.js, publicPath: '/static/js/', filename: '[name].js', }, module: { rules: [ { test: /\.js$/, exclude: /(node_modules)/, use: { loader: 'babel-loader', options: { cacheDirectory: true, }, }, }, ], }, resolve: { modules: ['node_modules', paths.src.js], }, plugins: basePlugins(), }; module.exports = config; ```
./_scripts/paths.js ```js const path = require('path'); // resource paths const DIR_SRC = path.join(__dirname, '..', 'src'); const DIR_DIST = path.join(__dirname, '..', 'dist'); // prettier-ignore exports.src = { js : DIR_SRC + '/js/', root : DIR_SRC + '/', }; // prettier-ignore exports.dist = { js : DIR_DIST + '/js/', root : DIR_DIST + '/', }; ```

Output:

image

image

The other manifest.json in /dist/ is from another build process, that needs to be concatenated to.

mastilver commented 6 years ago

What's your version of webpack-manifest-plugin?

ivancuric commented 6 years ago

"webpack-manifest-plugin": "^1.3.1",

mastilver commented 6 years ago

My bad..., I managed to reproduce it, I will try to have a look tonight

mastilver commented 6 years ago

So I find the reason why the tests are passing

The join function of https://github.com/webpack/webpack/blob/master/lib/MemoryOutputFileSystem.js and https://github.com/webpack/webpack/blob/master/lib/node/NodeOutputFileSystem.js are behaving defferently

memoryFs.join('/dir1', '/dir2/file') => /dir2/file path.join('/dir1', '/dir2/file') => /dir1/dir2/file

See: https://runkit.com/embed/yp5dtitvt668

ivancuric commented 6 years ago

Uh... That's weird.

mastilver commented 6 years ago

published v1.3.2