@storepress/create-plugin-html 0.0.6 → 0.1.0
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.
- package/README.md +3 -4
- package/index.js +10 -4
- package/package.json +1 -1
- package/plugin-templates/.eslintrc.js.mustache +1 -0
- package/plugin-templates/index-module.html.mustache +30 -0
- package/plugin-templates/index.html.mustache +47 -24
- package/plugin-templates/src/interactive/index.js.mustache +19 -0
- package/plugin-templates/src/react/index.js.mustache +38 -0
- package/{block-templates → plugin-templates/src/storepress}/Plugin.js.mustache +2 -2
- package/plugin-templates/src/storepress/index.js.mustache +20 -0
- package/plugin-templates/src/storepress/script.js.mustache +9 -0
- package/{block-templates → plugin-templates/src/storepress}/style.scss.mustache +2 -2
- package/plugin-templates/tools/webpack-helpers.js.mustache +10 -37
- package/plugin-templates/tools/webpack.config.externals.js.mustache +131 -0
- package/plugin-templates/webpack.config.js.mustache +95 -85
- package/block-templates/index.js.mustache +0 -20
- package/plugin-templates/global-style.css.mustache +0 -14
- package/plugin-templates/script.js.mustache +0 -8
- package/plugin-templates/style.scss.mustache +0 -10
- /package/{block-templates → plugin-templates/src/storepress}/_mixins.scss.mustache +0 -0
package/README.md
CHANGED
|
@@ -13,10 +13,9 @@ npx -y @wordpress/create-block@latest --template @storepress/create-plugin-html
|
|
|
13
13
|
Navigate to the newly created folder and get started.
|
|
14
14
|
|
|
15
15
|
```
|
|
16
|
-
npm i
|
|
17
|
-
npm run
|
|
18
|
-
|
|
19
|
-
npx -y http-server # Start Server
|
|
16
|
+
npm i && npm run packages-update # Install dependencies and Update package dependency
|
|
17
|
+
npm run build # Build the javascript
|
|
18
|
+
npx -y http-server # Start Server
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
## Development
|
package/index.js
CHANGED
|
@@ -38,8 +38,8 @@ module.exports = {
|
|
|
38
38
|
customScripts : {
|
|
39
39
|
'postinstall' : 'git init -q && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
40
40
|
|
|
41
|
-
'prebuild' : 'rimraf build',
|
|
42
|
-
'build' : '
|
|
41
|
+
'prebuild' : 'rimraf build && npm run external:build',
|
|
42
|
+
'build' : 'wp-scripts build --webpack-copy-php --experimental-modules',
|
|
43
43
|
|
|
44
44
|
'check-engines' : 'wp-scripts check-engines',
|
|
45
45
|
'check-licenses' : 'wp-scripts check-licenses',
|
|
@@ -73,10 +73,16 @@ module.exports = {
|
|
|
73
73
|
'test:e2e' : 'wp-scripts test-e2e',
|
|
74
74
|
'test:unit' : 'wp-scripts test-unit-js',
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
"external:dev": "wp-scripts start --no-watch --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
77
|
+
"external:build": "wp-scripts build --config tools/webpack.config.externals.js --experimental-modules --webpack-no-externals",
|
|
78
|
+
|
|
79
|
+
'prestart' : 'rimraf build && npm run external:dev',
|
|
80
|
+
'start' : 'wp-scripts start --webpack-copy-php --experimental-modules',
|
|
77
81
|
},
|
|
78
82
|
npmDependencies : [
|
|
79
83
|
'@storepress/utils',
|
|
84
|
+
'@wordpress/element',
|
|
85
|
+
'@wordpress/interactivity',
|
|
80
86
|
],
|
|
81
87
|
npmDevDependencies : [
|
|
82
88
|
'@wordpress/scripts',
|
|
@@ -109,7 +115,7 @@ module.exports = {
|
|
|
109
115
|
'zip' : [
|
|
110
116
|
'build/**',
|
|
111
117
|
'index.html',
|
|
112
|
-
'
|
|
118
|
+
'index-module.html',
|
|
113
119
|
],
|
|
114
120
|
},
|
|
115
121
|
transformer : (view) => {
|
package/package.json
CHANGED
|
@@ -161,6 +161,7 @@ module.exports = {
|
|
|
161
161
|
'lodash',
|
|
162
162
|
'jquery',
|
|
163
163
|
'@storepress/utils',
|
|
164
|
+
'@storepress/html-plugin', // See: getWebPackAlias() from tools/webpack-helpers.js
|
|
164
165
|
'@utils', // See: getWebPackAlias() from tools/webpack-helpers.js
|
|
165
166
|
],
|
|
166
167
|
'import/resolver': {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Standalone WordPress Package Usages</title>
|
|
7
|
+
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"@storepress/utils": "./build/storepress-utils-module.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<link rel="modulepreload" href="./build/storepress-utils-module.js" fetchpriority="low"/>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<h2>StorePress Example as Module:</h2>
|
|
22
|
+
|
|
23
|
+
<div data-storepress-plugin="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
24
|
+
|
|
25
|
+
<p><a href="./index.html">Check using storepress plugin as script</a></p>
|
|
26
|
+
|
|
27
|
+
<script type="module" src="./build/module-example.js"></script>
|
|
28
|
+
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -3,35 +3,58 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<link rel="modulepreload" href="./build/storepress-utils-module.js" />
|
|
22
|
-
<link rel="modulepreload" href="https://esm.sh/@huggingface/transformers" />
|
|
23
|
-
<link rel="modulepreload" href="https://esm.sh/@babycommando/entity-db" />
|
|
24
|
-
|
|
25
|
-
<script type="module" src="./custom-module.js"></script>
|
|
6
|
+
<title>Standalone WordPress Package Usages</title>
|
|
7
|
+
|
|
8
|
+
<script type="importmap">
|
|
9
|
+
{
|
|
10
|
+
"imports": {
|
|
11
|
+
"@wordpress/interactivity": "./build/externals/modules/wp-interactivity.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<link rel="modulepreload" href="./build/externals/modules/wp-interactivity.js" fetchpriority="low"/>
|
|
26
17
|
</head>
|
|
27
18
|
|
|
28
19
|
<body>
|
|
29
20
|
|
|
30
|
-
<
|
|
31
|
-
|
|
21
|
+
<h1>Example of WordPress Package Usage as Standalone</h1>
|
|
22
|
+
<div id="wrapper"></div>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
data-wp-interactive="my-app"
|
|
27
|
+
data-wp-context='{ "isOpen": false }'
|
|
28
|
+
>
|
|
29
|
+
<h2>Interactive Counter: <span data-wp-text="state.count"></span></h2>
|
|
30
|
+
<button data-wp-on--click="actions.increment">+</button>
|
|
31
|
+
<button data-wp-on--click="actions.decrement">−</button>
|
|
32
|
+
|
|
33
|
+
<hr>
|
|
34
|
+
|
|
35
|
+
<button data-wp-on--click="actions.toggle">
|
|
36
|
+
<span data-wp-text="state.toggleText"></span>
|
|
37
|
+
</button>
|
|
38
|
+
<p data-wp-bind--hidden="!context.isOpen">
|
|
39
|
+
Hello from the Interactivity API! 🎉
|
|
40
|
+
</p>
|
|
32
41
|
</div>
|
|
33
42
|
|
|
43
|
+
|
|
44
|
+
<h2>StorePress Example:</h2>
|
|
45
|
+
|
|
46
|
+
<div data-storepress-plugin="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
47
|
+
|
|
48
|
+
<p><a href="./index-module.html">Check using storepress plugin as module</a></p>
|
|
49
|
+
|
|
50
|
+
<script src="./build/externals/scripts/react-jsx-runtime.js"></script>
|
|
51
|
+
<script src="./build/externals/scripts/wp-element.js"></script>
|
|
52
|
+
<script src="./build/react-example.js"></script>
|
|
53
|
+
|
|
34
54
|
<script src="./build/storepress-utils.js"></script>
|
|
35
|
-
<script src="./build/
|
|
55
|
+
<script src="./build/script-example.js"></script>
|
|
56
|
+
|
|
57
|
+
<script type="module" src="./build/interactive-example.js"></script>
|
|
58
|
+
|
|
36
59
|
</body>
|
|
37
|
-
</html>
|
|
60
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { store, getContext } from '@wordpress/interactivity';
|
|
2
|
+
|
|
3
|
+
const { state } = store('my-app', {
|
|
4
|
+
state: {
|
|
5
|
+
count: 0,
|
|
6
|
+
get toggleText() {
|
|
7
|
+
const ctx = getContext();
|
|
8
|
+
return ctx.isOpen ? 'Hide' : 'Show';
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
actions: {
|
|
12
|
+
increment() { state.count++; },
|
|
13
|
+
decrement() { state.count--; },
|
|
14
|
+
toggle() {
|
|
15
|
+
const ctx = getContext();
|
|
16
|
+
ctx.isOpen = !ctx.isOpen;
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRoot, useState, StrictMode } from '@wordpress/element';
|
|
2
|
+
|
|
3
|
+
const App = () => {
|
|
4
|
+
const [count, setCount] = useState(0);
|
|
5
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
6
|
+
|
|
7
|
+
const toggleVisible = () => setIsVisible(!isVisible);
|
|
8
|
+
|
|
9
|
+
const toggleText = isVisible ? 'Hide' : 'Show';
|
|
10
|
+
|
|
11
|
+
const toggleStyle = {
|
|
12
|
+
display : isVisible ? 'block' : 'none'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<h2>React Counter: {count}</h2>
|
|
18
|
+
|
|
19
|
+
<button onClick={() => setCount(count + 1)}>+</button>
|
|
20
|
+
|
|
21
|
+
<button onClick={() => setCount(count - 1)}>-</button>
|
|
22
|
+
|
|
23
|
+
<hr/>
|
|
24
|
+
|
|
25
|
+
<button onClick={toggleVisible}> {toggleText} </button>
|
|
26
|
+
|
|
27
|
+
<p style={toggleStyle}>
|
|
28
|
+
Hello from the React API! 🎉
|
|
29
|
+
</p>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const container = document.getElementById('wrapper');
|
|
35
|
+
if (container) {
|
|
36
|
+
const root = createRoot(container);
|
|
37
|
+
root.render(<StrictMode><App/></StrictMode>);
|
|
38
|
+
}
|
|
@@ -10,7 +10,7 @@ export function Plugin (element, options) {
|
|
|
10
10
|
const PRIVATE = {}
|
|
11
11
|
|
|
12
12
|
// Collecting settings from html attribute
|
|
13
|
-
const ATTRIBUTE = 'plugin
|
|
13
|
+
const ATTRIBUTE = 'storepress-plugin' // html data-plugin-settings
|
|
14
14
|
|
|
15
15
|
const CLASSES = {
|
|
16
16
|
NEW: 'new-class',
|
|
@@ -86,4 +86,4 @@ export function Plugin (element, options) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
return init()
|
|
89
|
-
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createStorePressPlugin } from '@storepress/utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from './Plugin';
|
|
10
|
+
|
|
11
|
+
const HtmlPlugin = createStorePressPlugin({
|
|
12
|
+
selector : '[data-storepress-plugin]',
|
|
13
|
+
options : {},
|
|
14
|
+
plugin : Plugin,
|
|
15
|
+
namespace : 'html',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
HtmlPlugin.setup();
|
|
19
|
+
|
|
20
|
+
export default HtmlPlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
$default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
6
6
|
|
|
7
|
-
:where([data-
|
|
7
|
+
:where([data-storepress-plugin]) {
|
|
8
8
|
font-family: $default-font;
|
|
9
9
|
|
|
10
10
|
@include plugin.init();
|
|
@@ -12,4 +12,4 @@ $default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-San
|
|
|
12
12
|
& {
|
|
13
13
|
--custom-variable: 1px;
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|
|
@@ -19,22 +19,17 @@ const scriptHandleMap = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const externalModulesMap = {
|
|
22
|
-
// 1. static import.
|
|
23
|
-
// '@wordpress/a11y': 'import @wordpress/a11y',
|
|
24
|
-
// '@storepress/utils': 'import @storepress/utils',
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
// 'module @wordpress/a11y' → import * as X from '@wordpress/a11y'
|
|
24
|
+
// 'import @wordpress/a11y' → module.exports = import('@wordpress/a11y')
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
// '@storepress/utils': 'module @storepress/utils',
|
|
26
|
+
'@storepress/utils' : 'module @storepress/utils',
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// driver.connect();
|
|
28
|
+
// import('@storepress/utils').then(()=>{});
|
|
29
|
+
// OR
|
|
30
|
+
// const config = await fetch('../config.json').then(response => response.json());
|
|
31
|
+
// const driver = await import(`@storepress/utils`);
|
|
32
|
+
// driver.connect();
|
|
38
33
|
|
|
39
34
|
/*
|
|
40
35
|
```html
|
|
@@ -51,29 +46,7 @@ const externalModulesMap = {
|
|
|
51
46
|
<link rel="modulepreload" href="http://example.com/wp-includes/js/dist/script-modules/interactivity/index.min.js" fetchpriority="low" />
|
|
52
47
|
<link rel="modulepreload" href="./build/storepress-utils-module.js" fetchpriority="low" />
|
|
53
48
|
```*/
|
|
54
|
-
|
|
55
|
-
// in view.js
|
|
56
|
-
// ```js
|
|
57
|
-
// "import" prefix — static import (top-level, resolved at load time)
|
|
58
|
-
// import { store, getContext } from '@wordpress/a11y';
|
|
59
|
-
// ```
|
|
60
|
-
|
|
61
|
-
// dynamic import.
|
|
62
|
-
// @see: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query/view.js#L40
|
|
63
|
-
// ```js
|
|
64
|
-
// import('@wordpress/interactivity-router').then({});
|
|
65
|
-
// ```
|
|
66
|
-
// '@wordpress/interactivity-router': 'import @wordpress/interactivity-router',
|
|
67
|
-
|
|
68
|
-
// view.js
|
|
69
|
-
|
|
70
|
-
// "import" prefix — static import (top-level, resolved at load time)
|
|
71
|
-
// import { store, getContext } from '@wordpress/interactivity';
|
|
72
|
-
|
|
73
|
-
// "module" prefix — dynamic import (lazy, resolved at runtime)
|
|
74
|
-
// const loadRouter = () => import('@wordpress/interactivity-router');
|
|
75
|
-
}
|
|
76
|
-
;
|
|
49
|
+
};
|
|
77
50
|
|
|
78
51
|
/**
|
|
79
52
|
* Default request to global transformation
|
|
@@ -145,7 +118,7 @@ function getWebPackAlias() {
|
|
|
145
118
|
//'@storepress/icons': getFile('packages/icons'),
|
|
146
119
|
//'@storepress/utils': getFile('packages/utils'),
|
|
147
120
|
//'@storepress/components': getFile('packages/components'),
|
|
148
|
-
'@
|
|
121
|
+
'@storepress/html-plugin' : getFile('storepress/index.js'),
|
|
149
122
|
};
|
|
150
123
|
}
|
|
151
124
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const [
|
|
2
|
+
defaultJSConfig,
|
|
3
|
+
defaultModuleConfig,
|
|
4
|
+
] = require('@wordpress/scripts/config/webpack.config');
|
|
5
|
+
const {
|
|
6
|
+
requestToExternal,
|
|
7
|
+
requestToHandle,
|
|
8
|
+
requestToExternalModule,
|
|
9
|
+
getFile,
|
|
10
|
+
getRootFile,
|
|
11
|
+
getWebPackAlias,
|
|
12
|
+
} = require('./webpack-helpers');
|
|
13
|
+
const WoocommerceDependencyExtractionWebpackPlugin = require('@woocommerce/dependency-extraction-webpack-plugin');
|
|
14
|
+
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');
|
|
15
|
+
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
|
|
16
|
+
const webpack = require('webpack');
|
|
17
|
+
|
|
18
|
+
// Helper to route files to the correct directory
|
|
19
|
+
|
|
20
|
+
const getOutputFilename = (pathData) => {
|
|
21
|
+
|
|
22
|
+
const condition = (pathData.chunk.name.startsWith('wp-') || pathData.chunk.name.startsWith('react-'))
|
|
23
|
+
|
|
24
|
+
return condition
|
|
25
|
+
? `externals/scripts/[name].js`
|
|
26
|
+
: '[name].js';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getOutputFilenameAsModule = (pathData) => {
|
|
30
|
+
|
|
31
|
+
const condition = (pathData.chunk.name.startsWith('wp-') || pathData.chunk.name.startsWith('react-'))
|
|
32
|
+
|
|
33
|
+
return condition
|
|
34
|
+
? `externals/modules/[name].js`
|
|
35
|
+
: '[name].js';
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const scriptConfig = {
|
|
39
|
+
...defaultJSConfig,
|
|
40
|
+
entry : {
|
|
41
|
+
'wp-element' : {
|
|
42
|
+
import : '@wordpress/element',
|
|
43
|
+
library : {
|
|
44
|
+
name : ['wp', 'element'],
|
|
45
|
+
type : 'window'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
'react-jsx-runtime' : {
|
|
49
|
+
import : 'react/jsx-runtime',
|
|
50
|
+
library : {
|
|
51
|
+
name : ['ReactJSXRuntime'],
|
|
52
|
+
type : 'window',
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
output : {
|
|
58
|
+
...defaultJSConfig.output,
|
|
59
|
+
filename : getOutputFilename,
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
resolve : {
|
|
63
|
+
...defaultJSConfig.resolve,
|
|
64
|
+
alias : {
|
|
65
|
+
...defaultJSConfig.resolve.alias,
|
|
66
|
+
...getWebPackAlias(),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
plugins : [
|
|
71
|
+
...defaultJSConfig.plugins,
|
|
72
|
+
...defaultJSConfig.plugins.filter(
|
|
73
|
+
(plugin) =>
|
|
74
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
75
|
+
),
|
|
76
|
+
new webpack.optimize.LimitChunkCountPlugin({maxChunks : 1}),
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const moduleConfig = {
|
|
81
|
+
...defaultModuleConfig,
|
|
82
|
+
entry : {
|
|
83
|
+
// ...defaultModuleConfig.entry(),
|
|
84
|
+
// 'custom-module': getFile( 'custom-module.js' ),
|
|
85
|
+
/*'storepress-utils-module': {
|
|
86
|
+
import: '@storepress/utils/build-module/index.js',
|
|
87
|
+
library: {
|
|
88
|
+
type: 'module',
|
|
89
|
+
},
|
|
90
|
+
}*/
|
|
91
|
+
|
|
92
|
+
'wp-interactivity' : {
|
|
93
|
+
import : '@wordpress/interactivity',
|
|
94
|
+
library : {
|
|
95
|
+
type : 'module'
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
output : {
|
|
101
|
+
...defaultModuleConfig.output,
|
|
102
|
+
filename : getOutputFilenameAsModule,
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
resolve : {
|
|
106
|
+
...defaultModuleConfig.resolve,
|
|
107
|
+
alias : {
|
|
108
|
+
...defaultModuleConfig.resolve.alias,
|
|
109
|
+
...getWebPackAlias(),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
plugins : [
|
|
114
|
+
...defaultModuleConfig.plugins,
|
|
115
|
+
|
|
116
|
+
...defaultModuleConfig.plugins.filter(
|
|
117
|
+
(plugin) =>
|
|
118
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
119
|
+
),
|
|
120
|
+
|
|
121
|
+
new webpack.optimize.LimitChunkCountPlugin({maxChunks : 1}),
|
|
122
|
+
|
|
123
|
+
// Removes the empty `.js` files generated by webpack but
|
|
124
|
+
// sets it after WP has generated its `*.asset.php` file.
|
|
125
|
+
new RemoveEmptyScriptsPlugin({
|
|
126
|
+
stage : RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
|
|
127
|
+
}),
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
module.exports = [scriptConfig, moduleConfig];
|
|
@@ -1,104 +1,114 @@
|
|
|
1
1
|
const [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
]
|
|
2
|
+
defaultJSConfig,
|
|
3
|
+
defaultModuleConfig,
|
|
4
|
+
] = require('@wordpress/scripts/config/webpack.config');
|
|
5
5
|
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
const WoocommerceDependencyExtractionWebpackPlugin = require(
|
|
14
|
-
const DependencyExtractionWebpackPlugin
|
|
15
|
-
const RemoveEmptyScriptsPlugin
|
|
6
|
+
requestToExternal,
|
|
7
|
+
requestToHandle,
|
|
8
|
+
requestToExternalModule,
|
|
9
|
+
getFile,
|
|
10
|
+
getRootFile,
|
|
11
|
+
getWebPackAlias,
|
|
12
|
+
} = require('./tools/webpack-helpers');
|
|
13
|
+
const WoocommerceDependencyExtractionWebpackPlugin = require('@woocommerce/dependency-extraction-webpack-plugin');
|
|
14
|
+
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');
|
|
15
|
+
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
|
|
16
16
|
|
|
17
17
|
const scriptConfig = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
getRootFile('script.js'),
|
|
18
|
+
...defaultJSConfig,
|
|
19
|
+
entry : {
|
|
20
|
+
[`react-example`] : [
|
|
21
|
+
getFile('react/index.js'),
|
|
23
22
|
],
|
|
24
|
-
'storepress-utils': {
|
|
25
|
-
import: '@storepress/utils/build-module/index.js',
|
|
26
|
-
library: {
|
|
27
|
-
name: ['StorePress','Utils'],
|
|
28
|
-
type: 'window'
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
'storepress-utils' : {
|
|
25
|
+
import : '@storepress/utils/build-module/index.js',
|
|
26
|
+
library : {
|
|
27
|
+
name : ['StorePress', 'Utils'],
|
|
28
|
+
type : 'window',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
),
|
|
47
|
-
new WoocommerceDependencyExtractionWebpackPlugin( {
|
|
48
|
-
requestToExternal,
|
|
49
|
-
requestToHandle,
|
|
50
|
-
requestToExternalModule,
|
|
51
|
-
} ),
|
|
32
|
+
[`script-example`] : [
|
|
33
|
+
getFile('storepress/style.scss'),
|
|
34
|
+
getFile('storepress/script.js'),
|
|
35
|
+
],
|
|
36
|
+
},
|
|
52
37
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
38
|
+
resolve : {
|
|
39
|
+
...defaultJSConfig.resolve,
|
|
40
|
+
alias : {
|
|
41
|
+
...defaultJSConfig.resolve.alias,
|
|
42
|
+
...getWebPackAlias(),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
plugins : [
|
|
47
|
+
...defaultJSConfig.plugins,
|
|
48
|
+
...defaultJSConfig.plugins.filter(
|
|
49
|
+
(plugin) =>
|
|
50
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
51
|
+
),
|
|
52
|
+
|
|
53
|
+
new DependencyExtractionWebpackPlugin({
|
|
54
|
+
requestToExternal,
|
|
55
|
+
requestToHandle,
|
|
56
|
+
requestToExternalModule,
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
// Removes the empty `.js` files generated by webpack but
|
|
60
|
+
// sets it after WP has generated its `*.asset.php` file.
|
|
61
|
+
new RemoveEmptyScriptsPlugin({
|
|
62
|
+
stage : RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
}
|
|
60
66
|
|
|
61
67
|
const moduleConfig = {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// ...defaultModuleConfig.entry(),
|
|
67
|
-
// 'custom-module': getFile( 'custom-module.js' ),
|
|
68
|
-
/*'storepress-utils-module': {
|
|
68
|
+
...defaultModuleConfig,
|
|
69
|
+
entry : {
|
|
70
|
+
'interactive-example' : getFile('interactive/index.js'),
|
|
71
|
+
'storepress-utils-module': {
|
|
69
72
|
import: '@storepress/utils/build-module/index.js',
|
|
70
73
|
library: {
|
|
71
74
|
type: 'module',
|
|
72
75
|
},
|
|
73
|
-
}
|
|
74
|
-
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
[`module-example`] : [
|
|
79
|
+
getFile('storepress/style.scss'),
|
|
80
|
+
getFile('storepress/script.js'),
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
resolve : {
|
|
85
|
+
...defaultModuleConfig.resolve,
|
|
86
|
+
alias : {
|
|
87
|
+
...defaultModuleConfig.resolve.alias,
|
|
88
|
+
...getWebPackAlias(),
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
plugins : [
|
|
93
|
+
...defaultModuleConfig.plugins,
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
...getWebPackAlias(),
|
|
81
|
-
},
|
|
82
|
-
},
|
|
95
|
+
...defaultModuleConfig.plugins.filter(
|
|
96
|
+
(plugin) =>
|
|
97
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
98
|
+
),
|
|
83
99
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
),
|
|
90
|
-
new DependencyExtractionWebpackPlugin( {
|
|
91
|
-
requestToExternal,
|
|
92
|
-
requestToHandle,
|
|
93
|
-
requestToExternalModule,
|
|
94
|
-
} ),
|
|
100
|
+
new DependencyExtractionWebpackPlugin({
|
|
101
|
+
requestToExternal,
|
|
102
|
+
requestToHandle,
|
|
103
|
+
requestToExternalModule,
|
|
104
|
+
}),
|
|
95
105
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
// Removes the empty `.js` files generated by webpack but
|
|
107
|
+
// sets it after WP has generated its `*.asset.php` file.
|
|
108
|
+
new RemoveEmptyScriptsPlugin({
|
|
109
|
+
stage : RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
|
|
110
|
+
}),
|
|
111
|
+
],
|
|
102
112
|
};
|
|
103
113
|
|
|
104
|
-
module.exports = [
|
|
114
|
+
module.exports = [scriptConfig, moduleConfig];
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createStorePressPlugin } from '@storepress/utils';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { Plugin } from './Plugin';
|
|
10
|
-
|
|
11
|
-
const {{pascaleSlug}} = createStorePressPlugin( {
|
|
12
|
-
selector: '[data-{{kebabSlug}}]',
|
|
13
|
-
options: {},
|
|
14
|
-
plugin: Plugin,
|
|
15
|
-
namespace: '{{pascaleSlug}}',
|
|
16
|
-
} );
|
|
17
|
-
|
|
18
|
-
{{pascaleSlug}}.setup();
|
|
19
|
-
|
|
20
|
-
export default {{pascaleSlug}};
|
|
File without changes
|