Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
script-path
Advanced tools
Retrieves the path of the specified script on the page, used to dynamically load assets relative the current script.
Retrieves the path of the specified script on the page, used to dynamically load assets relative the current script.
npm install script-path --save
# bundleName is the final name of your bundle (without .min or .js)
var bundleName = 'app';
var scriptPath = require('script-path')(bundleName);
script-path returns the path to the script file as passed in, use it to load assets relative to your bundle, not to the page.
If your page is running at https://example.com/mypage
but it's loading your bundle from
https://cdn.somewhereelse.com/libs/myscript.min.js
, the following code will return
https://cdn.somewhereelse.com/libs/
.
var scriptPath = require('script-path')('myscript');
Webpack enables you to load chunks dynamically from your script, it uses a config setting publicPath
(https://github.com/webpack/docs/wiki/Configuration#outputpublicpath) to determine the path to load the chunks from,
however this means you either have to load them relative to the current page or know the exact URL at build time.
Rather than settings the publicPath
property you can include set the path at runtime by assigning it to
__webpack_public_path__
on your entry point. Using script-path you don't need to know where it's going to hosted
or where it's running from, you can query that at runtime, e.g.
__webpack_public_path__ = require('script-path')('myscript');
FAQs
Retrieves the path of the specified script on the page, used to dynamically load assets relative the current script.
The npm package script-path receives a total of 0 weekly downloads. As such, script-path popularity was classified as not popular.
We found that script-path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.