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

Copy before rest of build process? #286

Closed
martixy opened this issue Sep 7, 2018 · 6 comments
Closed

Copy before rest of build process? #286

martixy opened this issue Sep 7, 2018 · 6 comments

Comments

@martixy
Copy link

martixy commented Sep 7, 2018

I have a build dependency which needs to be copied over before the project can be built.

Currently the build fails, as it seems the plugin is running AFTER the rest of the build process.

Is there a setting, or something that would make the copy happen before the build?

My use case is a (not sure how well known in js-land) pattern of having a config.json.dist, which contains default values and having your build process create / merge new config options to config.js, which itself is gitignored.

Edit: Issue seems similar to this: #195
But I'm not sure of exactly identical. Though the solution he offered will probably help.
Though it is kind of ironic that I have to use the copy plugin to process some data and not be able to do it to actually copy a file.

@alexander-akait
Copy link
Member

PR welcome

@alexander-akait
Copy link
Member

Close in favor #195

@martixy
Copy link
Author

martixy commented Feb 22, 2019

Achieved this on my end with event hooks (like in 195).

But I still find it delightfully ironic that something named CopyWebpackPlugin doesn't actually Copy things. Like... what went wrong there?

@alexander-akait
Copy link
Member

@martixy What do you mean?

@marcelo2605
Copy link

@martixy could you share your solution?

@martixy
Copy link
Author

martixy commented Feb 11, 2020

@marcelo2605 My solution goes like this:

new EventHooksPlugin({
    compile: () => {
        console.log('Copying config.');
        if (!fs.existsSync(path.resolve(__dirname, 'config/config.json'))) {
            fs.copyFileSync(
                path.resolve(__dirname, 'config/config.json.dist'),
                path.resolve(__dirname, 'config/config.json')
            )
        } else {
            console.log('config.json exists, skipping copy.');
        }
    }
}),

@evilebottnawi What I mean is that I have to use the above approach instead of this:

{
    from: path.resolve(__dirname, 'config/config.json.dist'),
    to: path.resolve(__dirname, 'config/config.json'),
    force: false
}

because not only does the build process fail if it depends on the to file, but even if it did not fail, the to-file is overwritten if it exists, even though force is set to false. So yes, the irony is still going strong...

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

No branches or pull requests

3 participants