@sumotto/configs 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ const globby = require( 'globby' );
2
+ const rimraf = require( 'rimraf' );
3
+
4
+ let isRunning = false;
5
+
6
+ class CleanWebpackPlugin {
7
+ constructor( options ) {
8
+ this.patterns = options.patterns.map( ( pattern ) =>
9
+ pattern.replace( /\\/g, '/' )
10
+ );
11
+ }
12
+
13
+ // noinspection JSUnusedGlobalSymbols
14
+ apply( compiler ) {
15
+ compiler.hooks.beforeRun.tap( 'SumoTToCleanWebpackPlugin', () => {
16
+ this.del();
17
+ } );
18
+
19
+ compiler.hooks.watchRun.tap( 'SumoTToCleanWebpackPlugin', () => {
20
+ if ( isRunning ) {
21
+ return;
22
+ }
23
+
24
+ isRunning = true;
25
+
26
+ this.del();
27
+ } );
28
+ }
29
+
30
+ del() {
31
+ globby.sync( this.patterns ).forEach( ( file ) => {
32
+ rimraf.sync( file, { glob: false } );
33
+ } );
34
+ }
35
+ }
36
+
37
+ module.exports = CleanWebpackPlugin;
@@ -8,7 +8,7 @@ class SyncDirectoryWebpackPlugin {
8
8
  skipInitialSync: false,
9
9
  watch: true,
10
10
  deleteOrphaned: true,
11
- exclude: 'node_modules',
11
+ exclude: [ ...( options.exclude || [] ), 'node_modules' ],
12
12
  } );
13
13
  }
14
14
 
@@ -22,6 +22,7 @@ const [
22
22
 
23
23
  function getEntryName( entryPath ) {
24
24
  const entryData = path.parse( entryPath );
25
+
25
26
  return path
26
27
  .normalize(
27
28
  path.join(
@@ -54,7 +55,7 @@ module.exports.modulesConfigWP = modulesConfigWP;
54
55
 
55
56
  module.exports.Config = class {
56
57
  constructor( config, name, port = 'auto' ) {
57
- this.config = config;
58
+ this.config = { ...config };
58
59
  this.config.name = name;
59
60
  this.entries = {};
60
61
  this.entriesFunctions = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sumotto/configs",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Configs for my work",
5
5
  "scripts": {
6
6
  "release": "np --yolo"
@@ -29,12 +29,13 @@
29
29
  "@wordpress/scripts": "^28.2.0",
30
30
  "copy-webpack-plugin": "^12.0.2",
31
31
  "dotenv": "^16.4.5",
32
- "filemanager-webpack-plugin": "^8.0.0",
33
32
  "find-free-port-sync": "^1.0.0",
34
33
  "glob": "^10.4.2",
34
+ "globby": "^11.0.4",
35
35
  "image-minimizer-webpack-plugin": "^4.0.2",
36
36
  "mini-css-extract-plugin": "^2.9.0",
37
37
  "postcss-increase-specificity": "^0.6.0",
38
+ "rimraf": "^6.0.0",
38
39
  "rtlcss-webpack-plugin": "^4.0.7",
39
40
  "svgo": "^3.3.2",
40
41
  "sync-directory": "^6.0.5",
@@ -1,7 +1,6 @@
1
1
  const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
2
2
  const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
3
3
  const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
4
- const FileManagerPlugin = require( 'filemanager-webpack-plugin' );
5
4
  const SyncDirectoryWebpackPlugin = require( '../helpers/sync-directory-webpack-plugin' );
6
5
  const findFreePort = require( 'find-free-port-sync' );
7
6
  const { resolve } = require( 'node:path' );
@@ -10,6 +9,7 @@ const {
10
9
  defaultConfigWP,
11
10
  modulesConfigWP,
12
11
  } = require( '../helpers/webpack' );
12
+ const { CleanWebpackPlugin } = require( '../helpers/clean-webpack-plugin' );
13
13
  const root = process.cwd().replace( /\\/g, '/' );
14
14
 
15
15
  const port =
@@ -31,20 +31,18 @@ const defaultConfig = new Config( defaultConfigWP, 'default', port )
31
31
  } )
32
32
  )
33
33
  .addPlugin(
34
- new FileManagerPlugin( {
35
- events: {
36
- onStart: {
37
- delete: [
38
- {
39
- source: './build/*',
40
- options: {
41
- ignore: '**/module.*',
42
- },
43
- },
44
- ],
45
- },
46
- },
47
- runOnceInWatchMode: true,
34
+ new CleanWebpackPlugin( {
35
+ patterns: [
36
+ resolve(
37
+ process.env.WP_CONTENT_DIR,
38
+ 'plugins/theme-blocks/build/**/*'
39
+ ),
40
+ '!' +
41
+ resolve(
42
+ process.env.WP_CONTENT_DIR,
43
+ 'plugins/theme-blocks/build/**/module.*'
44
+ ),
45
+ ],
48
46
  } )
49
47
  );
50
48
 
@@ -53,33 +51,34 @@ if ( ! Config.hasDevServer( defaultConfigWP ) ) {
53
51
  // For styles remove JS and styles .asset.php
54
52
  new RemoveEmptyScriptsPlugin()
55
53
  );
56
- } else {
57
- defaultConfig.addWatch( 'src/blocks/*/scripts/module.{j,t}s' );
58
54
  }
59
55
 
60
56
  const modulesConfig = new Config( modulesConfigWP, 'modules' ).addPlugin(
61
- new FileManagerPlugin( {
62
- events: {
63
- onStart: {
64
- delete: [
65
- {
66
- source: '**/module.*',
67
- options: {},
68
- },
69
- ],
70
- },
71
- },
72
- runOnceInWatchMode: true,
57
+ new CleanWebpackPlugin( {
58
+ patterns: [
59
+ resolve(
60
+ process.env.WP_CONTENT_DIR,
61
+ 'plugins/theme-blocks/build/**/module.*'
62
+ ),
63
+ ],
73
64
  } )
74
65
  );
75
66
 
76
67
  if ( process.env.WP_CONTENT_DIR ) {
68
+ const buildPath = resolve(
69
+ process.env.WP_CONTENT_DIR,
70
+ 'plugins/theme-blocks/build'
71
+ );
72
+ defaultConfigWP.output.path = buildPath;
73
+ modulesConfigWP.output.path = buildPath;
74
+
77
75
  const syncDirectory = new SyncDirectoryWebpackPlugin( {
78
76
  sourceDir: root,
79
77
  targetDir: resolve(
80
78
  process.env.WP_CONTENT_DIR,
81
79
  'plugins/theme-blocks'
82
80
  ),
81
+ exclude: [ /build/ ],
83
82
  } );
84
83
 
85
84
  defaultConfig.addPlugin( syncDirectory );
@@ -3,7 +3,7 @@ const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
3
3
  const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
4
4
  const ImageMinimizerPlugin = require( 'image-minimizer-webpack-plugin' );
5
5
  const SyncDirectoryWebpackPlugin = require( '../helpers/sync-directory-webpack-plugin' );
6
- const FileManagerPlugin = require( 'filemanager-webpack-plugin' );
6
+ const { CleanWebpackPlugin } = require( '../helpers/clean-webpack-plugin' );
7
7
  const findFreePort = require( 'find-free-port-sync' );
8
8
  const { resolve } = require( 'node:path' );
9
9
  const {
@@ -32,20 +32,18 @@ const defaultConfig = new Config( defaultConfigWP, 'default', port )
32
32
  } )
33
33
  .removePlugin( RtlCssPlugin )
34
34
  .addPlugin(
35
- new FileManagerPlugin( {
36
- events: {
37
- onStart: {
38
- delete: [
39
- {
40
- source: './build/*',
41
- options: {
42
- ignore: './build/scripts/modules/**/*',
43
- },
44
- },
45
- ],
46
- },
47
- },
48
- runOnceInWatchMode: true,
35
+ new CleanWebpackPlugin( {
36
+ patterns: [
37
+ resolve(
38
+ process.env.WP_CONTENT_DIR,
39
+ 'themes/theme-child/build/**/*'
40
+ ),
41
+ '!' +
42
+ resolve(
43
+ process.env.WP_CONTENT_DIR,
44
+ 'themes/theme-child/build/modules/**/*'
45
+ ),
46
+ ],
49
47
  } )
50
48
  )
51
49
  .addPlugin(
@@ -119,25 +117,28 @@ const modulesConfig = new Config( modulesConfigWP, 'modules' )
119
117
  .resetEntries()
120
118
  .addEntries( 'src/scripts/modules/*.{j,t}s' )
121
119
  .addPlugin(
122
- new FileManagerPlugin( {
123
- events: {
124
- onStart: {
125
- delete: [
126
- {
127
- source: './build/scripts/modules/*',
128
- options: {},
129
- },
130
- ],
131
- },
132
- },
133
- runOnceInWatchMode: true,
120
+ new CleanWebpackPlugin( {
121
+ patterns: [
122
+ resolve(
123
+ process.env.WP_CONTENT_DIR,
124
+ 'themes/theme-child/build/scripts/modules/**/*'
125
+ ),
126
+ ],
134
127
  } )
135
128
  );
136
129
 
137
130
  if ( process.env.WP_CONTENT_DIR ) {
131
+ const buildPath = resolve(
132
+ process.env.WP_CONTENT_DIR,
133
+ 'themes/theme-child/build'
134
+ );
135
+ defaultConfigWP.output.path = buildPath;
136
+ modulesConfigWP.output.path = buildPath;
137
+
138
138
  const syncDirectory = new SyncDirectoryWebpackPlugin( {
139
139
  sourceDir: root,
140
140
  targetDir: resolve( process.env.WP_CONTENT_DIR, 'themes/theme-child' ),
141
+ exclude: [ '/build/' ],
141
142
  } );
142
143
 
143
144
  defaultConfig.addPlugin( syncDirectory );