I am using react-scripts in my project. I use some newer syntax that requires my webpack.config use plugins such as
plugins: ['transform-decorators-legacy']
I am trying to avoid ejecting the config files just to add this line to the webpack.config.dev and webpack.config.prod files.
So I am trying to make a script to insert this automatically.
In the dev file, I need to insert it after the cacheDirectory: true.
// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true
}
}
And I have come up with this to insert it
"fix-react-scripts-dev": "ex -sc '%s/cacheDirectory: true/cacheDirectory: true,plugins: ['transform-decorators-legacy']/g|x' node_modules/react-scripts/config/webpack.config.dev.js"
The result is
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
query: {
// @remove-on-eject-begin
babelrc: false,
presets: [require.resolve('babel-preset-react-app')],
// @remove-on-eject-end
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
plugins: [transform-decorators-legacy]
}
}
the problem is
plugins: [transform-decorators-legacy]
is missing the quotation marks. Is this a character escape issue I am missing from my script?
And for the prod config file. I need to insert it after
presets: [require.resolve('babel-preset-react-app')]
// Process JS with Babel.
{
test: /\.(js|jsx)$/,
include: paths.appSrc,
loader: 'babel',
// @remove-on-eject-begin
query: {
babelrc: false,
presets: [require.resolve('babel-preset-react-app')]
}
// @remove-on-eject-end
}