-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
85 lines (76 loc) · 1.83 KB
/
index.js
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
79
80
81
82
83
84
85
const mix = require("laravel-mix");
const JavaScript = require("laravel-mix/src/components/JavaScript");
const DependencyExtractionPlugin = require("@wordpress/dependency-extraction-webpack-plugin");
/**
* Laravel Mix WP Block
*
* @see https://laravel-mix.com/docs/5.0/extending-mix
* @see https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin
*/
class Block extends JavaScript {
constructor() {
super();
this.context = Mix;
}
name() {
return ["blocks", "block"];
}
/**
* All dependencies that should be installed by Mix.
*
* @return {array}
*/
dependencies() {
this.requiresReload = `
Dependencies have been installed. Please run again.
`;
return [
"@wordpress/babel-preset-default",
"@wordpress/dependency-extraction-webpack-plugin",
];
}
/**
* Register the plugin component.
*
* @param {string} entry
* @param {string} output
* @param {object} options
* @return {void}
*/
register(entry, output, options = {}) {
this.pluginOptions =
options.disableRegenerator === true
? {
...options,
requestToExternal: function (request) {
if (request === "@babel/runtime/regenerator") {
return null;
}
},
}
: options;
super.register(entry, output);
}
/**
* Plugins to be merged with the master webpack config.
*
* @return {array|object}
*/
webpackPlugins() {
return new DependencyExtractionPlugin({
...this.pluginOptions,
});
}
/**
* Babel config to be merged with the master Babel config.
*
* @return {object}
*/
babelConfig() {
return {
presets: ["@wordpress/babel-preset-default"],
};
}
}
mix.extend("block", new Block());
mix.extend("blocks", new Block());