Comments (2)
Hi,
Thanks for asking. So with the PHP API, say you want to enqueue. Then you do something like this
$enqueue = new \WPackio\Enqueue( 'appName', 'dist', '1.0.0', 'plugin', PLUGIN_PATH );
$assets = $enqueue->enqueue( 'app', 'main', [
'js' => true,
'css' => true,
'js_dep' => [],
'css_dep' => [],
'in_footer' => true,
'media' => 'all',
] );
Now if you store the return value of enqueue
, ($assets
in the example), you will get the handle and URL of all the assets. Like
[
'js' => [
[
'handle' => 'wpackio_fooapp_path/to/foo.js_script',
'url' => 'http://example.com/path/to/foo.js',
],
[
'handle' => 'wpackio_fooapp_path/to/bar.js_script',
'url' => 'http://example.com/path/to/bar.js',
],
],
'css' => [
[
'handle' => 'wpackio_fooapp_path/to/foo.css_style',
'url' => 'http://example.com/path/to/foo.css',
],
[
'handle' => 'wpackio_fooapp_path/to/bar.css_style',
'url' => 'http://example.com/path/to/bar.css',
],
],
];
Now the last item of each js
and css
arrays is the final handle where you would want to attach localize_script
. So something like
$entry_point = array_pop( $assets['js'] );
wp_localize_script( $entry_point['handle'], 'objectName', $localization );
The same concept is true for getAssets
, enqueue
and register
methods.
I hope it makes sense.
It would be awesome if I can get a PR from you about this. You can add a new file localize-script.md
with the same formatting of any existing file in this directory
https://github.com/swashata/wp-webpack-script/tree/master/site/docs/tutorials
The site will be updated automatically.
from wp-webpack-script.
This has been published https://wpack.io/tutorials/localize-script/
from wp-webpack-script.
Related Issues (20)
- The manifest.json file updates without running build HOT 6
- Caching Plugins and ContentHash HOT 6
- Dependency Dashboard
- Asset name with ~ (6G Firewall - 403 error) HOT 3
- Issue with JSX? HOT 2
- Recipe for SSG / Static html generation and preload HOT 3
- 403 Forbidden on vendors script file HOT 1
- Strange enqueue behaviour, with nothing being enqueued at all. Needs fix in Enqueue.php:297 source HOT 2
- Shortcode params HOT 1
- [fork-ts-checker-webpack-plugin] breaking change in 7.0 HOT 1
- bannerConfig should not default if not filled, it should be left out
- Typescript not working HOT 6
- wpack project in subdirectory results in broken asset paths
- update to webpack 5 HOT 3
- Conflict with React Router 6
- Conflicting file-loader documentation
- Wp
- How to make server works on docker
- Is this project dead? HOT 4
- Not able to setup site on the local system. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-webpack-script.