mirror of
https://github.com/infeng/react-viewer.git
synced 2025-12-08 17:36:40 +00:00
feat: extract css make ssr work
This commit is contained in:
parent
901d4aa108
commit
d97e7f7429
@ -20,6 +20,7 @@ npm install react-viewer --save
|
||||
```javascript
|
||||
import * as React from 'react';
|
||||
import Viewer from 'react-viewer';
|
||||
import 'react-viewer/dist/index.css';
|
||||
|
||||
function App() {
|
||||
const [ visible, setVisible ] = React.useState(false);
|
||||
|
||||
12
package-lock.json
generated
12
package-lock.json
generated
@ -10827,6 +10827,18 @@
|
||||
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==",
|
||||
"dev": true
|
||||
},
|
||||
"mini-css-extract-plugin": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "http://bnpm.byted.org/mini-css-extract-plugin/download/mini-css-extract-plugin-0.9.0.tgz",
|
||||
"integrity": "sha1-R/LPB6oWWrNXM7H8l9TEbAVkM54=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loader-utils": "^1.1.0",
|
||||
"normalize-url": "1.9.1",
|
||||
"schema-utils": "^1.0.0",
|
||||
"webpack-sources": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"mini-store": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mini-store/-/mini-store-2.0.0.tgz",
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
"less": "^3.10.3",
|
||||
"less-loader": "^5.0.0",
|
||||
"merge2": "^1.3.0",
|
||||
"mini-css-extract-plugin": "^0.9.0",
|
||||
"postcss-loader": "^3.0.0",
|
||||
"pre-commit": "^1.1.3",
|
||||
"react": "^16.10.2",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const React = require('react');
|
||||
const Viewer = require('./dist/index');
|
||||
const Viewer = require('../dist/index').default;
|
||||
|
||||
function App () {
|
||||
const [ visible, setVisible ] = React.useState(false);
|
||||
@ -18,7 +18,7 @@ function App () {
|
||||
return (
|
||||
<div>
|
||||
<button onClick={() => { setVisible(true); }}>{visible ? 'close' : 'open'}</button>
|
||||
<Viewer images={images} visible={visible} />
|
||||
<Viewer images={images} visible={visible} onClose={() => { setVisible(false); }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
const React = require('react');
|
||||
const ReactDOM = require('react-dom');
|
||||
const App = require('./app');
|
||||
import '../dist/index.css';
|
||||
|
||||
ReactDOM.hydrate(<App />, document.getElementById('root'));
|
||||
|
||||
3975
ssr-test/package-lock.json
generated
3975
ssr-test/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -8,9 +8,7 @@
|
||||
"dependencies": {
|
||||
"@babel/cli": "^7.5.5",
|
||||
"@babel/node": "^7.5.5",
|
||||
"express": "^4.17.1",
|
||||
"react": "^16.10.2",
|
||||
"react-dom": "^16.10.2"
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
|
||||
@ -14,13 +14,24 @@ module.exports = {
|
||||
test: /\.js$/,
|
||||
use: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
}, {
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'style-loader',
|
||||
},
|
||||
{
|
||||
loader: 'css-loader',
|
||||
},
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
}
|
||||
],
|
||||
},
|
||||
devtool: 'cheap-module-eval-source-map',
|
||||
resolve: {
|
||||
extensions: [ '.js' ],
|
||||
modules: [path.join(__dirname, 'node_modules')],
|
||||
modules: [path.join(__dirname, 'node_modules'), path.join(__dirname, '../node_modules')],
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
const path = require('path');
|
||||
const Config = require('webpack-chain');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
|
||||
const DEFAULT_BROWSERS = [
|
||||
'>1%',
|
||||
@ -54,8 +55,8 @@ config.module
|
||||
config.module
|
||||
.rule('less')
|
||||
.test(/\.less/)
|
||||
.use('style-loader')
|
||||
.loader('style-loader')
|
||||
.use('MiniCssExtractPlugin.loader')
|
||||
.loader(MiniCssExtractPlugin.loader)
|
||||
.end()
|
||||
.use('css-loader')
|
||||
.loader('css-loader')
|
||||
@ -132,4 +133,7 @@ config.resolve
|
||||
.end()
|
||||
.modules.add(path.join(__dirname, 'node_modules'));
|
||||
|
||||
config.plugin('MiniCssExtractPlugin')
|
||||
.use(MiniCssExtractPlugin)
|
||||
|
||||
module.exports = config;
|
||||
|
||||
@ -11,6 +11,7 @@ if (fs.existsSync(distPath)) {
|
||||
config.output.merge({
|
||||
library: 'react-viewer',
|
||||
libraryTarget: 'umd',
|
||||
globalObject: 'this'
|
||||
});
|
||||
|
||||
config.mode('production');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user