![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
asset-module-webpack-plugin
Advanced tools
A webpack plugin that emits JS modules for your assets such as images. This allows Node to load the modules that webpack generated for your assets without having to run webpack's bundle on the server.
A webpack plugin that emits JS modules for your assets such as images. This allows Node to load the modules that webpack generated for your assets without having to run webpack's bundle on the server.
This plugin was written to facilitate server-side rendering of React components. The traditional approach is to build two webpack bundles, one for the browser and one for the server. This works, but there a few things about it that are unappealing:
What we really wanted to do was run our JS files on Node directly instead of a bundle. The enhanced-require package looks like the most comprehensive solution, as it polyfills webpack for the server. However, it is unmaintained, and we needed only two features anyway: We wanted to be able to require CSS/LESS files without throwing an error, and we wanted require('./icon.png')
to return the full CDN path to the icon. My goal was for this code to run:
import './Button.less';
class Button extends React.Component {
render() {
return (
<button className="button">
<img src={require('./icon.png')} className="button-icon" />
{this.props.text}
</button>
);
}
}
The plugin runs after compilation and translates the path of the source asset to a destination path (you configure this with the sourceBase
and destinationBase
options). It then writes the full path of the asset to a file at the destination path. It emit files like this:
// build/icon.png
// It's actually a JS module with a png extension, which Node can evaluate. The
// full asset path is derived from the public path and asset's relative path.
module.exports = "http://static.example.com/eelZITCY0q9Gbj00z8HI.png";
In your webpack configuration file, add this to your list of plugins:
new AssetModulePlugin({
sourceBase: path.join(__dirname, 'src'),
destinationBase: path.join(__dirname, 'build'),
test: /\.(?!js)$/,
exclude: /node_modules/,
fileSystems: [AssetModulePlugin.DefaultFileSystem, require('fs')],
})
This takes your assets whose filenames don't end in ".js" and aren't under "node_modules" and moves them from "src" to "build". The original asset's path relative to "src" will be the same as the emitted module's path relative to "build".
We use the class
keyword so io.js 2.0+ is required.
If you have ideas for how to improve server-side rendering we'd be happy to chat. Open up a GitHub issue or join our Slack chat at http://exp.host/community.
Run npm run-script build
to build lib
from src
.
FAQs
A webpack plugin that emits JS modules for your assets such as images. This allows Node to load the modules that webpack generated for your assets without having to run webpack's bundle on the server.
The npm package asset-module-webpack-plugin receives a total of 34 weekly downloads. As such, asset-module-webpack-plugin popularity was classified as not popular.
We found that asset-module-webpack-plugin 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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.