-
Notifications
You must be signed in to change notification settings - Fork 428
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
Custom output name based on package name and version when building #301
Comments
Can't support config questions here: Maybe: |
@timarney Thanks. By reading both that link and your own documentation I finally figured it out. /* config-overrides.js */
const version = require('./package.json').version;
const buildFileName = `simulator-v${version}`;
module.exports = function override(config, env) {
// Change the JS output file name and path, from 'static/js/[name].[contenthash:8].js' to `static/${buildFileName}.js`
config.output = {
...config.output,
filename: `static/${buildFileName}.js`,
};
// Change the CSS output file name and path, from 'static/css/[name].[contenthash:8].css' to `static/${buildFileName}.css`
config.plugins.map((plugin, i) => {
if (plugin.filename && plugin.filename.includes('static/css')) {
config.plugins[i].filename = `static/${buildFileName}.css`;
}
});
console.log('Additional config was applied through config-overrides.js');
return config;
}; I suggest you add this to the readme, because I noticed several people were asking for this and I couldn't find a proper answer. Also, my fix is kind of a workaround, may break depending on plugins (I don't know a proper way of identifying a plugin, to replace the file name of the generated CSS file) |
@Vadorequest not sure if this totally solves the issue as I faced two problems with this solution
/* config-overrides.js */ |
… building Steps: - yarn add react-app-rewired -D - yarn add @babel/runtime - add config-overrides.js Refs: https://github.com/timarney/react-app-rewired https://webpack.js.org/configuration/entry-context/#naming Multiple entries rewire error: Cannot read property 'filter' of undefined timarney/react-app-rewired#421 https://github.com/vl4d1m1r4/cra-multi-entry/blob/8c62e9168e638e4c841fff87291cec6a99eb4ea9/config-overrides.js Disabling code splitting in CRA2 facebook/create-react-app#5306 Setting up a template with React-App-Rewired https://dev.to/aryclenio/part-3-setting-up-a-template-with-react-app-rewired-3e9j Custom output name based on package name and version when building timarney/react-app-rewired#301 How do I build js and css without random number? facebook/create-react-app#1005 A way to defined the bundle filename? facebook/create-react-app#4156 https://medium.com/@ryoldash/customize-webpack-config-of-react-app-created-with-create-react-app-7a78c7849edc https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
Is there a way of customizing the output file when running the build command?
cross-env REACT_APP_NAME=$npm_package_name REACT_APP_VERSION=$npm_package_version react-app-rewired build
this is what I'm doing now but it generates amain.c3jfhd.js
, I'd rather like a different name, can I customize it somehow?Thanks.
The text was updated successfully, but these errors were encountered: