@sumotto/configs 0.0.14 → 0.0.16

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,26 @@
1
+ const syncDirectory = require( 'sync-directory' );
2
+
3
+ class SyncDirectoryWebpackPlugin {
4
+ constructor( options ) {
5
+ this.sourceDir = options.sourceDir;
6
+ this.targetDir = options.targetDir;
7
+ this.watcher = syncDirectory( this.sourceDir, this.targetDir, {
8
+ skipInitialSync: false,
9
+ watch: true,
10
+ deleteOrphaned: true,
11
+ exclude: 'node_modules',
12
+ } );
13
+ }
14
+
15
+ // noinspection JSUnusedGlobalSymbols
16
+ apply( compiler ) {
17
+ compiler.hooks.done.tap( 'SyncDirectoryPlugin', () => {
18
+ if ( 'development' !== compiler.options.mode ) {
19
+ // noinspection JSUnresolvedReference
20
+ this.watcher.close();
21
+ }
22
+ } );
23
+ }
24
+ }
25
+
26
+ module.exports = SyncDirectoryWebpackPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sumotto/configs",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Configs for my work",
5
5
  "scripts": {
6
6
  "release": "np --yolo"
@@ -34,8 +34,10 @@
34
34
  "glob": "^10.4.2",
35
35
  "image-minimizer-webpack-plugin": "^4.0.2",
36
36
  "mini-css-extract-plugin": "^2.9.0",
37
+ "postcss-increase-specificity": "^0.6.0",
37
38
  "rtlcss-webpack-plugin": "^4.0.7",
38
39
  "svgo": "^3.3.2",
40
+ "sync-directory": "^6.0.5",
39
41
  "webpack-remove-empty-scripts": "^1.0.4"
40
42
  },
41
43
  "eslintConfig": {
@@ -0,0 +1,32 @@
1
+ module.exports = ( api ) => {
2
+ const isProduction = api.mode === 'production';
3
+
4
+ return {
5
+ ident: 'postcss',
6
+ sourceMap: ! isProduction,
7
+ plugins: [
8
+ [ 'autoprefixer', { grid: true } ],
9
+ [
10
+ 'postcss-increase-specificity',
11
+ {
12
+ repeat: 1,
13
+ overrideIds: false,
14
+ stackableRoot: ':is(.is-root-container,.wp-site-blocks)',
15
+ },
16
+ ],
17
+ isProduction && [
18
+ 'cssnano',
19
+ {
20
+ preset: [
21
+ 'default',
22
+ {
23
+ discardComments: {
24
+ removeAll: true,
25
+ },
26
+ },
27
+ ],
28
+ },
29
+ ],
30
+ ],
31
+ };
32
+ };
@@ -2,6 +2,7 @@ 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
4
  const FileManagerPlugin = require( 'filemanager-webpack-plugin' );
5
+ const SyncDirectoryWebpackPlugin = require( '../helpers/sync-directory-webpack-plugin' );
5
6
  const findFreePort = require( 'find-free-port-sync' );
6
7
  const { resolve } = require( 'node:path' );
7
8
  const {
@@ -9,6 +10,7 @@ const {
9
10
  defaultConfigWP,
10
11
  modulesConfigWP,
11
12
  } = require( '../helpers/webpack' );
13
+ const root = process.cwd().replace( /\\/g, '/' );
12
14
 
13
15
  const port =
14
16
  process.env.THEME_BLOCK_DEV_SERVER_PORT ||
@@ -72,83 +74,16 @@ const modulesConfig = new Config( modulesConfigWP, 'modules' ).addPlugin(
72
74
  );
73
75
 
74
76
  if ( process.env.WP_CONTENT_DIR ) {
75
- defaultConfig
76
- .addPlugin(
77
- new FileManagerPlugin( {
78
- events: {
79
- onStart: {
80
- delete: [
81
- {
82
- source: resolve(
83
- process.env.WP_CONTENT_DIR,
84
- 'plugins/theme-blocks'
85
- ),
86
- options: {
87
- force: true,
88
- },
89
- },
90
- ],
91
- },
92
- },
93
- runOnceInWatchMode: true,
94
- } )
95
- )
96
- .addPlugin(
97
- new FileManagerPlugin( {
98
- events: {
99
- onEnd: {
100
- copy: [
101
- {
102
- source: '**/*',
103
- destination: resolve(
104
- process.env.WP_CONTENT_DIR,
105
- 'plugins/theme-blocks'
106
- ),
107
- },
108
- ],
109
- },
110
- },
111
- } )
112
- );
77
+ const syncDirectory = new SyncDirectoryWebpackPlugin( {
78
+ sourceDir: root,
79
+ targetDir: resolve(
80
+ process.env.WP_CONTENT_DIR,
81
+ 'plugins/theme-blocks'
82
+ ),
83
+ } );
113
84
 
114
- modulesConfig
115
- .addPlugin(
116
- new FileManagerPlugin( {
117
- events: {
118
- onStart: {
119
- delete: [
120
- {
121
- source: resolve(
122
- process.env.WP_CONTENT_DIR,
123
- 'plugins/theme-blocks'
124
- ),
125
- options: {
126
- force: true,
127
- },
128
- },
129
- ],
130
- },
131
- },
132
- runOnceInWatchMode: true,
133
- } )
134
- )
135
- .addPlugin(
136
- new FileManagerPlugin( {
137
- events: {
138
- onEnd: {
139
- copy: [
140
- {
141
- source: '**/*',
142
- destination: resolve(
143
- process.env.WP_CONTENT_DIR,
144
- 'plugins/theme-blocks'
145
- ),
146
- },
147
- ],
148
- },
149
- },
150
- } )
151
- );
85
+ defaultConfig.addPlugin( syncDirectory );
86
+ modulesConfig.addPlugin( syncDirectory );
152
87
  }
153
88
 
154
89
  module.exports = [ defaultConfig.get(), modulesConfig.get() ];
@@ -2,15 +2,16 @@ const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
2
2
  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
+ const SyncDirectoryWebpackPlugin = require( '../helpers/sync-directory-webpack-plugin' );
5
6
  const FileManagerPlugin = require( 'filemanager-webpack-plugin' );
6
- const { resolve } = require( 'node:path' );
7
7
  const findFreePort = require( 'find-free-port-sync' );
8
+ const { resolve } = require( 'node:path' );
8
9
  const {
9
10
  Config,
10
11
  defaultConfigWP,
11
12
  modulesConfigWP,
12
13
  } = require( '../helpers/webpack' );
13
- const root = process.cwd();
14
+ const root = process.cwd().replace( /\\/g, '/' );
14
15
 
15
16
  const port =
16
17
  process.env.THEME_DEV_SERVER_PORT ||
@@ -21,6 +22,7 @@ const defaultConfig = new Config( defaultConfigWP, 'default', port )
21
22
  .addEntries(
22
23
  'src/styles/{*.{pc,sc,sa,c}ss,{blocks,variations,patterns}/**/*.{pc,sc,sa,c}ss}'
23
24
  )
25
+ .addEntries( 'src/scripts/*.{j,t}s' )
24
26
  .changeRule( '/\\.(sc|sa)ss$/', ( rule ) => {
25
27
  const last = rule.use.length - 1;
26
28
 
@@ -133,83 +135,13 @@ const modulesConfig = new Config( modulesConfigWP, 'modules' )
133
135
  );
134
136
 
135
137
  if ( process.env.WP_CONTENT_DIR ) {
136
- defaultConfig
137
- .addPlugin(
138
- new FileManagerPlugin( {
139
- events: {
140
- onStart: {
141
- delete: [
142
- {
143
- source: resolve(
144
- process.env.WP_CONTENT_DIR,
145
- 'themes/theme-child'
146
- ),
147
- options: {
148
- force: true,
149
- },
150
- },
151
- ],
152
- },
153
- },
154
- runOnceInWatchMode: true,
155
- } )
156
- )
157
- .addPlugin(
158
- new FileManagerPlugin( {
159
- events: {
160
- onEnd: {
161
- copy: [
162
- {
163
- source: '**/*',
164
- destination: resolve(
165
- process.env.WP_CONTENT_DIR,
166
- 'themes/theme-child'
167
- ),
168
- },
169
- ],
170
- },
171
- },
172
- } )
173
- );
138
+ const syncDirectory = new SyncDirectoryWebpackPlugin( {
139
+ sourceDir: root,
140
+ targetDir: resolve( process.env.WP_CONTENT_DIR, 'themes/theme-child' ),
141
+ } );
174
142
 
175
- modulesConfig
176
- .addPlugin(
177
- new FileManagerPlugin( {
178
- events: {
179
- onStart: {
180
- delete: [
181
- {
182
- source: resolve(
183
- process.env.WP_CONTENT_DIR,
184
- 'themes/theme-child'
185
- ),
186
- options: {
187
- force: true,
188
- },
189
- },
190
- ],
191
- },
192
- },
193
- runOnceInWatchMode: true,
194
- } )
195
- )
196
- .addPlugin(
197
- new FileManagerPlugin( {
198
- events: {
199
- onEnd: {
200
- copy: [
201
- {
202
- source: '**/*',
203
- destination: resolve(
204
- process.env.WP_CONTENT_DIR,
205
- 'themes/theme-child'
206
- ),
207
- },
208
- ],
209
- },
210
- },
211
- } )
212
- );
143
+ defaultConfig.addPlugin( syncDirectory );
144
+ modulesConfig.addPlugin( syncDirectory );
213
145
  }
214
146
 
215
147
  module.exports = [ defaultConfig.get(), modulesConfig.get() ];