Skip to content

Commit

Permalink
comment out 4.x plugins for time being, got copy plugin to work with …
Browse files Browse the repository at this point in the history
…monorepos too!
  • Loading branch information
aruniverse committed Mar 24, 2022
1 parent eb74552 commit 2e2b1f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
37 changes: 26 additions & 11 deletions packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironme
const SpeedMeasureWebpackPlugin = require('speed-measure-webpack-plugin');
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

const {
BanBackendImportsPlugin,
CopyBentleyStaticResourcesPlugin,
CopyStaticAssetsPlugin,
} = require('@itwin/core-webpack-tools');
const CopyPlugin = require("copy-webpack-plugin");
// const {
// BanBackendImportsPlugin,
// CopyBentleyStaticResourcesPlugin,
// CopyStaticAssetsPlugin,
// } = require('@itwin/core-webpack-tools');

// iModel.js change to support using the fast-sass-loader instead of sass-loader.
// This solves long build times on smaller machines attempting to build an app with
Expand All @@ -63,8 +64,6 @@ const shouldTranspileDeps = process.env.TRANSPILE_DEPS !== 'false';

const shouldMinify = process.env.DISABLE_TERSER !== 'true';

const disableNewAssetCopy = process.env.DISABLE_NEW_ASSET_COPY === 'true';

// End iModel.js Changes block

// Source maps are resource heavy and can cause out of memory issue for large source files.
Expand Down Expand Up @@ -287,6 +286,23 @@ module.exports = function (webpackEnv) {
? fastSassLoaderConfig
: 'sass-loader';

const copyPluginPatterns = Object.keys(require(paths.appPackageJson).dependencies)
.filter(dependency => dependency.startsWith('@bentley') || dependency.startsWith('@itwin'))
.map(dependency => {
return {
from: "**/public/**",
noErrorOnMissing: true,
context: path.dirname(require.resolve(`${dependency}/package.json`)),
globOptions: {
ignore: ["**/node_modules/**"],
},
to({ absoluteFilename }) {
const regex = new RegExp("(public(?:\\\\|\/))(.*)");
return regex.exec(absoluteFilename)[2];
},
};
});

const rawConfig = {
target: ['browserslist'],
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
Expand Down Expand Up @@ -436,7 +452,8 @@ module.exports = function (webpackEnv) {
},
plugins: [
// Throw an error if @bentley/imodeljs-backend or src/backend/... files are imported.
new BanBackendImportsPlugin(path.join(paths.appSrc, 'backend')),
// new BanBackendImportsPlugin(path.join(paths.appSrc, 'backend')),

// Prevents users from importing files from outside of src/ (or node_modules/).
// This often causes confusion because we only process files within src/ with babel.
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
Expand Down Expand Up @@ -749,9 +766,7 @@ module.exports = function (webpackEnv) {
// NOTE: iModel.js specific plugin to copy a set of static resources from the node_modules
// directory of each dependent package into the 'build/public' directory.
// Used for resources such as locales, which are defined by each consuming package.
disableNewAssetCopy
? new CopyBentleyStaticResourcesPlugin(['public'], true)
: new CopyStaticAssetsPlugin({}),
new CopyPlugin({ patterns: copyPluginPatterns }),

// NOTE: FilterWarningsPlugin is used to ignore warning coming from sourcemaps
new FilterWarningsPlugin({ exclude: /Failed to parse source map/ }),
Expand Down
3 changes: 2 additions & 1 deletion packages/react-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bentley/react-scripts",
"version": "5.0.0-dev.1",
"version": "5.0.0-dev.2",
"description": "iTwin.js configuration and scripts for Create React App.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -41,6 +41,7 @@
"browserslist": "^4.18.1",
"camelcase": "^6.2.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"copy-webpack-plugin": "^10.2.4",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^3.2.0",
"dotenv": "^10.0.0",
Expand Down

0 comments on commit 2e2b1f8

Please sign in to comment.