-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack.config.js
More file actions
69 lines (68 loc) · 2.25 KB
/
Copy pathwebpack.config.js
File metadata and controls
69 lines (68 loc) · 2.25 KB
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
const path = require('path');
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');
const { requestToExternal, requestToHandle } = require('./webpack-dependency-mapping');
module.exports = {
...defaultConfig,
entry: {
index: './src/index.tsx',
// Reusable components exposed for add-ons (window.texty.components).
components: {
import: './src/components/index.tsx',
library: {
name: ['texty', 'components'],
type: 'window',
},
},
// The plugin-ui kit exposed for add-ons (window.texty.pluginUi), so lite and
// every add-on share one copy instead of bundling their own.
//
// Both imports are resolved to absolute paths on purpose: the bare
// '@wedevs/plugin-ui' request is externalized by requestToExternal, so
// importing it by name here would make this entry externalize to itself.
// The package's JS comes last — webpack takes the library exports from the
// last module of a multi-import entry.
'plugin-ui': {
import: [
require.resolve('@wedevs/plugin-ui/styles.css'),
require.resolve('@wedevs/plugin-ui'),
],
library: {
name: ['texty', 'pluginUi'],
type: 'window',
},
},
},
output: {
...defaultConfig.output,
path: path.resolve(__dirname, 'dist'),
},
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename],
},
},
resolve: {
...defaultConfig.resolve,
extensions: [...(defaultConfig.resolve?.extensions || []), '.ts', '.tsx'],
alias: {
...(defaultConfig.resolve?.alias || {}),
'@': path.resolve(__dirname, 'src'),
},
},
watchOptions: {
ignored: ["**/dist/**"], // Ignore the generated build files to avoid unnecessary rebuilds
},
plugins: [
// Replace the default dependency-extraction plugin with one that also knows
// how to externalize Texty's own packages (@texty/*) for add-ons.
...defaultConfig.plugins.filter(
(plugin) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
),
new DependencyExtractionWebpackPlugin({
requestToExternal,
requestToHandle,
}),
],
};