Skip to content

Commit 2343746

Browse files
committed
Fix bundler not working correctly with new folder structure.
1 parent 146b4b7 commit 2343746

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

config/webpack-css.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'path'
2-
import { Configuration } from 'webpack'
2+
import { Configuration, EntryObject } from 'webpack'
33
import { Config as PostCssConfig } from 'postcss-load-config'
44
import libsass from 'sass'
55
import cssnano from 'cssnano'
@@ -20,21 +20,21 @@ const postcssOptions: PostCssConfig = {
2020
]
2121
}
2222

23+
const entriesFromFiles = (patterns: string | string[], entry: (filename: string) => string): EntryObject =>
24+
Object.fromEntries(
25+
glob.sync(patterns)
26+
.map(filename => [entry(filename), `./${filename}`])
27+
)
28+
2329
export const cssWebpackConfig: Configuration = {
2430
entry: {
25-
...Object.fromEntries(
26-
glob.sync(['src/css/*.scss', '!src/css/**/_*.scss'])
27-
.map(filename => {
28-
const name = path.parse(filename).name
29-
return [`${name}-style`, `./${filename}`]
30-
})
31+
...entriesFromFiles(
32+
['src/css/*.scss', '!src/css/**/_*.scss'],
33+
filename => `${path.parse(filename).name}-style`
3134
),
32-
...Object.fromEntries(
33-
glob.sync('node_modules/codemirror/theme/*.css')
34-
.map(filename => {
35-
const name = path.parse(filename).name
36-
return [`codemirror-theme-${name}`, `./${filename}`]
37-
})
35+
...entriesFromFiles(
36+
'node_modules/codemirror/theme/*.css',
37+
filename => `codemirror-theme-${path.parse(filename).name}`
3838
)
3939
},
4040
module: {

scripts/bundle.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ export const createArchive = (): Promise<void> => {
5252
}
5353

5454
const bundle = async () => {
55-
console.info('\ngenerating composer and webpack files\n')
55+
console.info('generating composer and webpack files\n')
5656

5757
await Promise.all([
5858
cleanup(`${plugin.name}.*.zip`),
5959
execute('composer', 'install', '--no-dev'),
6060
webpack({ mode: 'production' })
6161
])
6262

63-
await copy(BUNDLE_FILES, DEST_DIR)
64-
await createArchive()
63+
await copy(BUNDLE_FILES, DEST_DIR, filename =>
64+
filename.replace(/^src\//, ''))
6565

66+
await createArchive()
6667
await execute('composer', 'install')
6768
}
6869

scripts/utils/files.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const cleanup = (...paths: string[]): Promise<Awaited<void>[]> =>
1111
rm(resolve(filename), { force: true, recursive: true })
1212
))
1313

14-
export const copy = async (patterns: string[], dest: string): Promise<void> => {
14+
export const copy = async (patterns: string[], dest: string, transform?: (filename: string) => string): Promise<void> => {
1515
const filenames = glob(patterns)
1616
await rm(dest, { force: true, recursive: true })
1717
await mkdir(dest, { recursive: true })
@@ -21,7 +21,7 @@ export const copy = async (patterns: string[], dest: string): Promise<void> => {
2121

2222
if (!stats.isDirectory()) {
2323
console.log(`copying ${filename}`)
24-
const destPath = resolve(dest, filename)
24+
const destPath = resolve(dest, transform?.(filename) ?? filename)
2525

2626
await mkdir(dirname(destPath), { recursive: true })
2727
const out = createWriteStream(destPath, 'utf8')

webpack.config.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ import { merge } from 'webpack-merge'
33
import { cssWebpackConfig } from './config/webpack-css'
44
import { jsWebpackConfig } from './config/webpack-js'
55

6-
const devConfig: Configuration = {}
6+
const config: Configuration = {
7+
mode: 'development'
8+
}
79

8-
const prodConfig: Configuration = {}
9-
10-
const config = (_env: unknown, argv: Record<string, string>): Configuration =>
11-
merge(
12-
cssWebpackConfig,
13-
jsWebpackConfig,
14-
'development' === argv.mode ? devConfig : prodConfig
15-
)
16-
17-
export default config
10+
export default merge(cssWebpackConfig, jsWebpackConfig, config)

0 commit comments

Comments
 (0)