-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathwebpack-js.ts
78 lines (75 loc) · 1.85 KB
/
webpack-js.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { join, resolve } from 'path'
import { DefinePlugin } from 'webpack'
import ESLintPlugin from 'eslint-webpack-plugin'
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'
import { toCamelCase } from '../src/js/utils/text'
import { dependencies } from '../package.json'
import type { Configuration } from 'webpack'
const SOURCE_DIR = './src/js'
const DEST_DIR = './src/dist'
const babelConfig = {
presets: [
'@babel/preset-env',
'@wordpress/babel-preset-default'
],
plugins: [
['prismjs', {
languages: ['php', 'php-extras'],
plugins: ['line-highlight', 'line-numbers']
}]
]
}
export const jsWebpackConfig: Configuration = {
entry: {
edit: { import: `${SOURCE_DIR}/edit.tsx`, dependOn: 'editor' },
editor: `${SOURCE_DIR}/editor.ts`,
manage: `${SOURCE_DIR}/manage.ts`,
mce: `${SOURCE_DIR}/mce.ts`,
prism: `${SOURCE_DIR}/prism.ts`,
settings: { import: `${SOURCE_DIR}/settings.ts`, dependOn: 'editor' }
},
output: {
path: join(resolve(__dirname), '..', DEST_DIR),
filename: '[name].js',
clean: true
},
externalsType: 'window',
externals: {
'react': 'React',
'react-dom': 'ReactDOM',
'jquery': 'jQuery',
'tinymce': 'tinymce',
'codemirror': ['wp', 'CodeMirror'],
...Object.fromEntries(
Object.keys(dependencies)
.filter(name => name.startsWith('@wordpress/'))
.map(packageName => [
packageName,
['wp', toCamelCase(packageName.replace('@wordpress/', ''))]
])
)
},
resolve: {
modules: [resolve(__dirname, '..', 'node_modules')],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: babelConfig
}
}
]
},
plugins: [
new DefinePlugin({
'process.arch': JSON.stringify('x64')
}),
new ESLintPlugin(),
new RemoveEmptyScriptsPlugin()
]
}