Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mangled output #21

Closed
jknight12882 opened this issue Jul 7, 2016 · 5 comments · Fixed by #56 or #85
Closed

Mangled output #21

jknight12882 opened this issue Jul 7, 2016 · 5 comments · Fixed by #56 or #85

Comments

@jknight12882
Copy link

jknight12882 commented Jul 7, 2016

In multi compiler mode with a shared cache, I am getting the following mangled output.

{
  "common_en-US.js": "common_en-US-cbe78523083d0159240f.js",
  "common_en-US.js.map": "common_en-US-cbe78523083d0159240f.js.map"
}  "common_fr-CA.js": "common_fr-CA-2cf11bd51dc92d8b0ee2.js",
  "common_fr-CA.js.map": "common_fr-CA-2cf11bd51dc92d8b0ee2.js.map"
}

This is inconsistent, sometimes the file is correct, sometimes it is as above

@jknight12882
Copy link
Author

Config file for reference

import webpack from 'webpack';
import path from 'path';
import ManifestPlugin from 'webpack-manifest-plugin';

import locales from './locales';

const common = (locale, cache) => ({
    // verbose: true,
    devtool: 'source-map',
    entry: {
        [`common_${locale}`]: [
            ...
        ]
    },
    output: {
        filename: '[name]-[chunkhash].js',
        library: 'common',
        path: path.resolve(__dirname, '../dist/public/js')
    },
    resolve: {
        root: path.resolve(__dirname, '../src'),
        modulesDirectories: ['node_modules'],
        extensions: ['', '.json', '.js']
    },
    plugins: [
        new ManifestPlugin({
            cache,
            fileName: 'common-manifest.json'
        }),
        new webpack.DllReferencePlugin({
            context: path.resolve(__dirname, '..'),
            manifest: require(path.resolve(__dirname, '../.build/dll/react-manifest.json'))
        }),
        new webpack.DllPlugin({
            path: path.resolve(__dirname, '../.build/dll/[name]-manifest.json'),
            name: 'common',
            context: path.resolve(__dirname, '..')
        })
    ]
});

const dev = () => {
    const cache = { };

    return locales.map(locale => common(locale, cache));
};

const prod = () => {
    const cache = { };

    return locales.map(locale => {
        const config = Object.assign(common(locale, cache), {
            devtool: 'hidden-source-map'
        });

        config.plugins.push(
            new webpack.DefinePlugin({
                'process.env.NODE_ENV': JSON.stringify('production')
            }),
            new webpack.optimize.OccurrenceOrderPlugin(),
            new webpack.optimize.DedupePlugin(),
            new webpack.optimize.UglifyJsPlugin({
                sourceMap: true,
                compress: {
                    warnings: false
                }
            })
        );

        return config;
    });
};

export default (process.env.NODE_ENV === 'production') ? prod : dev;

@karlshea
Copy link

I'm also occasionally having the same issue. One build will be fine, the next will have a bad closing brace in the middle of the list.

@mastilver mastilver added the bug label Jul 4, 2017
@mastilver
Copy link
Contributor

I know it won't be easy (and I'm not sure if feasible... :/), but it would be a great help if you could send me a failing PR reproducing the issue

@mastilver
Copy link
Contributor

mastilver commented Aug 14, 2017

I'm reopening this one as I'm reverting the earlier fix, as it was causing another issue...

@mastilver mastilver reopened this Aug 14, 2017
@mastilver mastilver removed the has pr label Aug 14, 2017
@mastilver mastilver removed this from the v1.3 milestone Aug 14, 2017
@mastilver
Copy link
Contributor

So i now understand better how this issue is happening:

It's caused by this: /~https://github.com/webpack/webpack/blob/ef6ab6820a74db730cfec6fd419d2c211d62c0bd/lib/Compiler.js#L343

What's happening, is that webpack is writing the same file multiple times

To prevent that, we need to use /~https://github.com/mafintosh/mutexify to lock: /~https://github.com/danethurber/webpack-manifest-plugin/blob/1d691af97b955cc8c1c8cd5b684e54a81c7d0a3d/lib/plugin.js#L161 and release it on after-emit event

I will now focus on 2.x release, but if anyone feels like it, they can send us a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants