代码拉取完成,页面将自动刷新
A lightweight solution for the server-side rendering of webpack-built applications.
With webpack, we can require any files by using loaders:
// CSS Modules
// @see https://www.npmjs.com/package/css-loader#modules
import style from './css/style.css';
// Require a image file
<img src={require('./img/avatar.jpg')} />
But you'll get an error in server-side rendering, because it is not supported by Node.js.
webpack-isomorphic
is a lightweight, easy-to-use solution to solve this issue, and make your client-side codes work on server too.
# for webpack 4
npm install --save webpack-isomorphic@4
# for webpack 3
npm install --save webpack-isomorphic@3
const IsomorphicPlugin = require('webpack-isomorphic/plugin');
const isomorphicPlugin = new IsomorphicPlugin({
extensions: ['jpg', 'png', 'gif', 'css'],
// assetsFilePath: 'webpack.assets.json'
});
module.exports = {
// The base directory of your source files
context: __dirname + '/src',
// ...
plugins: [
//...
isomorphicPlugin
]
};
const webpackIsomorphic = require('webpack-isomorphic');
// The base directory of your built files
webpackIsomorphic.install(__dirname + '/dist', {
cache: process.env['NODE_ENV'] !== 'development',
// assetsFilePath: __dirname + '/dist/webpack.assets.json'
});
//...
Enjoy!
See the example project for more details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型