Skip to content

Commit

Permalink
sync spec/dummy & generator webpacker config
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Dec 22, 2021
1 parent 07e0600 commit 1786326
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ const { devServer, inliningCss } = require('@rails/webpacker');
const webpackConfig = require('./webpackConfig');

const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
// eslint-disable-next-line no-unused-vars
const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;

// plugins
if (inliningCss) {
// Note, when this is run, we're building the server and client bundles in separate processes.
// Thus, this plugin is not applied.
// Thus, this plugin is not applied to the server bundle.

// eslint-disable-next-line global-require
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
Expand All @@ -26,4 +23,5 @@ const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
);
}
};

module.exports = webpackConfig(developmentEnvOnly);
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/serverWebpackConfig.js") %>

// eslint-disable-next-line no-unused-vars
const { merge, config } = require('@rails/webpacker');
const commonWebpackConfig = require('./commonWebpackConfig');

Expand Down Expand Up @@ -31,7 +30,6 @@ const configureServer = () => {
// replace file-loader with null-loader
serverWebpackConfig.module.rules.forEach((loader) => {
if (loader.use && loader.use.filter) {
// eslint-disable-next-line no-param-reassign
loader.use = loader.use.filter(
(item) => !(typeof item === 'string' && item.match(/mini-css-extract-plugin/)),
);
Expand Down Expand Up @@ -69,11 +67,10 @@ const configureServer = () => {
// Remove the mini-css-extract-plugin from the style loaders because
// the client build will handle exporting CSS.
// replace file-loader with null-loader
const { rules } = serverWebpackConfig.module;
const rules = serverWebpackConfig.module.rules;
rules.forEach((rule) => {
if (Array.isArray(rule.use)) {
// remove the mini-css-extract-plugin and style-loader
// eslint-disable-next-line no-param-reassign
rule.use = rule.use.filter((item) => {
let testValue;
if (typeof item === 'string') {
Expand All @@ -100,7 +97,6 @@ const configureServer = () => {

// Skip writing image files during SSR by setting emitFile to false
} else if (rule.use && (rule.use.loader === 'url-loader' || rule.use.loader === 'file-loader')) {
// eslint-disable-next-line no-param-reassign
rule.use.options.emitFile = false;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/development.js") %>

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

const { devServer, inliningCss } = require('@rails/webpacker');

const webpackConfig = require('./webpackConfig');

const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
// place any code here that is for test only
};

module.exports = webpackConfig(developmentEnvOnly);
3 changes: 2 additions & 1 deletion spec/dummy/config/webpack/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
// plugins
if (inliningCss) {
// Note, when this is run, we're building the server and client bundles in separate processes.
// Thus, this plugin is not applied.
// Thus, this plugin is not applied to the server bundle.

// eslint-disable-next-line global-require
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
Expand All @@ -21,4 +21,5 @@ const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => {
);
}
};

module.exports = webpackConfig(developmentEnvOnly);
2 changes: 0 additions & 2 deletions spec/dummy/config/webpack/production.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production';

// Below code should get refactored but the current way that rails/webpacker v5
// does the globals, it's tricky
const webpackConfig = require('./webpackConfig');

const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => {
Expand Down

0 comments on commit 1786326

Please sign in to comment.