Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat ssr plugin #1187

Merged
merged 58 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fba5ee1
feat: add ssr plugin
Jul 31, 2019
9277be0
fix: fix document
Aug 1, 2019
57eb5ae
fix: fix ssr dev
Aug 1, 2019
0dc3779
feat: plugin app add export
Aug 1, 2019
fe37e73
fix: fix weex
Aug 1, 2019
052298e
feat: server side render
chenjun1011 Aug 1, 2019
b095e3a
fix: conflict
chenjun1011 Aug 1, 2019
e91073d
feat: custom server
Orange-C Aug 1, 2019
66b4de0
refactor: ssr dev config
chenjun1011 Aug 1, 2019
20a9949
refactor: dev server config
chenjun1011 Aug 2, 2019
93bc0d4
fix: conflict
chenjun1011 Aug 2, 2019
3f6ab41
refactor: dependencies for ssr
chenjun1011 Aug 2, 2019
248b134
refactor: documents props
chenjun1011 Aug 2, 2019
5f7dc81
fix: ssr public path
chenjun1011 Aug 2, 2019
ee3c98c
fix: conflict
chenjun1011 Aug 2, 2019
7607c78
feat: minimize in ssr
chenjun1011 Aug 2, 2019
3a8f05e
feat: ingnore css in ssr
chenjun1011 Aug 2, 2019
3c36ccd
refactor: web config in ssr
chenjun1011 Aug 2, 2019
a8f7d21
chore: merge
chenjun1011 Aug 2, 2019
324ae7b
revert: ignore css in ssr
chenjun1011 Aug 2, 2019
7500552
feat: add SSR client
fyangstudio Aug 2, 2019
8695c62
Merge branch 'feat-ssr-plugin' into feat-ss-plugin-client
fyangstudio Aug 2, 2019
cd5db2f
fix: delete web config
fyangstudio Aug 2, 2019
fe6ca82
feat: add page getInitialProps
fyangstudio Aug 2, 2019
008b253
feat: update
fyangstudio Aug 2, 2019
f457904
fix: lint
fyangstudio Aug 2, 2019
ef97e85
fix: update
fyangstudio Aug 2, 2019
9bbb250
Merge pull request #1196 from alibaba/feat-ss-plugin-client
chenjun1011 Aug 4, 2019
6a102e2
fix: hmr in ssr
chenjun1011 Aug 4, 2019
19371cb
refactor: get initial props
chenjun1011 Aug 4, 2019
78ed252
fix: hrm in ssr
chenjun1011 Aug 4, 2019
ce13c82
feat: support inline style
chenjun1011 Aug 4, 2019
7c55ab1
refactor: initial data
chenjun1011 Aug 4, 2019
f75036a
fix: getInitalProps
chenjun1011 Aug 4, 2019
a41de00
fix: css entry
chenjun1011 Aug 4, 2019
0e01693
feat: add router InitialComponent
fyangstudio Aug 4, 2019
777ef65
feat: add pwa
fyangstudio Aug 5, 2019
cd175fd
feat: getCurrentComponent fn only run ssr
fyangstudio Aug 5, 2019
2e79d70
Merge branch 'feat-ssr-plugin' into feat-ss-plugin-client
fyangstudio Aug 5, 2019
b435b55
feat: update
fyangstudio Aug 5, 2019
d3d4a33
feat: update appshell props
fyangstudio Aug 5, 2019
811a3b2
fix: package.json position
fyangstudio Aug 5, 2019
850cf01
fix: regext
fyangstudio Aug 5, 2019
7131e73
feat: add comment
fyangstudio Aug 5, 2019
52389f6
Merge pull request #1200 from alibaba/feat-ss-plugin-client
chenjun1011 Aug 5, 2019
4c2c17b
chore: merge feat-rax-engineering
chenjun1011 Aug 5, 2019
443db34
feat: support inline style in ssr
chenjun1011 Aug 5, 2019
46dde92
feat: get publicPath from user config
chenjun1011 Aug 5, 2019
fdceca7
feat: merge main
Orange-C Aug 6, 2019
78ca1c0
revert: external rax
chenjun1011 Aug 6, 2019
586dede
fix: description
chenjun1011 Aug 6, 2019
e344bb7
fix: fix webpack log
Orange-C Aug 6, 2019
95af237
Merge branch 'feat-ssr-plugin' of github.com:alibaba/rax into feat-ss…
Orange-C Aug 6, 2019
4709643
refactor: rename initial component
chenjun1011 Aug 6, 2019
136c8fa
Merge branch 'feat-ssr-plugin' of https://github.com/alibaba/rax into…
chenjun1011 Aug 6, 2019
071e8d8
fix: remove .temp
chenjun1011 Aug 6, 2019
5754a7d
refactor: get style config from userConfig
chenjun1011 Aug 6, 2019
673741f
chore: update version
chenjun1011 Aug 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rax-cli/src/generator/app/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"driver-universal": "^1.0.1",
"history": "^4.9.0",
"rax": "^1.0.8",
<%_ if (projectTargets.includes('web')) { -%>
"rax-pwa": "^1.0.2",
<%_ } -%>
"rax-view": "^1.0.0",
"rax-text": "^1.0.0",
"universal-app-runtime": "^0.1.3"
Expand Down
3 changes: 3 additions & 0 deletions packages/rax-cli/src/generator/app/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<%_ const isSSR = projectFeatures.includes('ssr') -%>
{
<%_ if (isSSR) { -%>
"inlineStyle": true,
chenjun1011 marked this conversation as resolved.
Show resolved Hide resolved
<%_ } -%>
"plugins": [
["rax-plugin-app", { "targets": ["<%- projectTargets.join('", "') %>"]}]<%_ if (isSSR) { -%>,<%_ } %>
<%_ if (isSSR) { -%>
Expand Down
4 changes: 4 additions & 0 deletions packages/rax-cli/src/generator/app/src/app.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%_ const isSSR = projectFeatures.includes('ssr') -%>
{
"routes": [
{
Expand All @@ -9,6 +10,9 @@
"component": "pages/about"
}
],
<%_ if (isSSR) { -%>
"historyType": "browser",
<%_ } -%>
"window": {
"defaultTitle": "Rax App 1.0"
}
Expand Down
6 changes: 2 additions & 4 deletions packages/rax-cli/src/generator/app/src/document/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ function Document(props) {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<title>WebApp</title>
<link href={`${publicPath}web/index.css`} rel="stylesheet" />
</head>
<body>
{/* root container */}
<div id="root" dangerouslySetInnerHTML={{ __html: initialHtml || '' }} />
<script src={`${publicPath}web/index.js`} />
{/* initial data from server side */}
<script data-from="server" type="application/json" dangerouslySetInnerHTML={{__html: initialData}} />
<script data-from="server" dangerouslySetInnerHTML={{__html: 'window.__INITIAL_DATA__=' + initialData}} />
<script src={`${publicPath}web/index.js`} />
</body>
</html>
);
Expand All @@ -36,7 +35,6 @@ function Document(props) {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<title>WebApp</title>
<link href={`${publicPath}web/index.css`} rel="stylesheet" />
</head>
<body>
{/* root container */}
Expand Down
71 changes: 43 additions & 28 deletions packages/rax-plugin-app/src/config/web/getBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const path = require('path');
const webpack = require('webpack');
const serverRender = require('rax-server-renderer');
const babelMerge = require('babel-merge');
Expand All @@ -16,7 +17,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const getWebpackBase = require('../getWebpackBase');

module.exports = (context) => {
const { rootDir } = context;
const { rootDir, userConfig } = context;

const config = getWebpackBase(context);

Expand All @@ -27,28 +28,20 @@ module.exports = (context) => {
.set('@core/page', 'universal-app-runtime')
.set('@core/router', 'universal-app-runtime');

config.module.rule('jsx')
.test(/\.(js|mjs|jsx)$/)
.exclude
.add(/(node_modules|bower_components)/)
.end()
.use('babel')
.loader(require.resolve('babel-loader'))
.options(babelConfigWeb);

config.module.rule('tsx')
.test(/\.tsx?$/)
.exclude
.add(/(node_modules|bower_components)/)
.end()
.use('babel')
.loader(require.resolve('babel-loader'))
.options(babelConfigWeb)
.end()
.use('ts')
.loader(require.resolve('ts-loader'));
let babelConfig = babelConfigWeb;
if (userConfig.inlineStyle) {
babelConfig = babelMerge.all([{
plugins: [
require.resolve('babel-plugin-transform-jsx-stylesheet')
],
}, babelConfig]);

config.module.rule('css')
config.module.rule('css')
.test(/\.css?$/)
.use('css')
.loader(require.resolve('stylesheet-loader'));
} else {
config.module.rule('css')
.test(/\.css?$/)
.use('minicss')
.loader(MiniCssExtractPlugin.loader)
Expand All @@ -71,6 +64,34 @@ module.exports = (context) => {
],
});

config.plugin('minicss')
.use(MiniCssExtractPlugin, [{
filename: 'web/[name].css',
chunkFilename: 'web/[name].css',
}]);
}

config.module.rule('jsx')
.test(/\.(js|mjs|jsx)$/)
.exclude
.add(/(node_modules|bower_components)/)
.end()
.use('babel')
.loader(require.resolve('babel-loader'))
.options(babelConfig);

config.module.rule('tsx')
.test(/\.tsx?$/)
.exclude
.add(/(node_modules|bower_components)/)
.end()
.use('babel')
.loader(require.resolve('babel-loader'))
.options(babelConfig)
.end()
.use('ts')
.loader(require.resolve('ts-loader'));

config.module.rule('assets')
.test(/\.(svg|png|webp|jpe?g|gif)$/i)
.use('source')
Expand All @@ -95,12 +116,6 @@ module.exports = (context) => {
render: serverRender.renderToString,
}]);

config.plugin('minicss')
.use(MiniCssExtractPlugin, [{
filename: 'web/[name].css',
chunkFilename: 'web/[id].css',
}]);

config.plugin('noError')
.use(webpack.NoEmitOnErrorsPlugin);

Expand Down
1 change: 1 addition & 0 deletions packages/rax-plugin-app/src/config/web/setDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = (config, context) => {
.contentBase(path.resolve(rootDir, 'build'))
.watchContentBase(true)
.hot(true)
.quiet(true)
.publicPath(publicPath)
.overlay(false)
.host(address.ip())
Expand Down
1 change: 1 addition & 0 deletions packages/rax-plugin-app/src/config/weex/setDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = (config, context) => {
.contentBase(path.resolve(rootDir, 'build'))
.watchContentBase(true)
.hot(true)
.quiet(true)
.publicPath(publicPath)
.overlay(false)
.host(address.ip())
Expand Down
12 changes: 11 additions & 1 deletion packages/rax-plugin-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultUserConfig = require('./config/defaultUserConfig');
const build = require('./build');
const dev = require('./dev');

module.exports = (api, options) => {
const pluginApp = (api, options) => {
const { context } = api;
const { command } = context;
// set default config
Expand All @@ -18,3 +18,13 @@ module.exports = (api, options) => {
dev(api, options);
}
};

pluginApp.getWebBase = require('./config/web/getBase');
pluginApp.setWebDev = require('./config/web/setDev');
pluginApp.setWebBuild = require('./config/web/setBuild');

pluginApp.getWeexBase = require('./config/weex/getBase');
pluginApp.setWeexDev = require('./config/weex/setDev');
pluginApp.setWeexBuild = require('./config/weex/setBuild');

module.exports = pluginApp;
48 changes: 48 additions & 0 deletions packages/rax-plugin-ssr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "rax-plugin-ssr",
"version": "0.1.0-0",
"description": "rax ssr plugins",
"license": "BSD-3-Clause",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/alibaba/rax.git"
},
"bugs": {
"url": "https://github.com/alibaba/rax/issues"
},
"homepage": "https://github.com/alibaba/rax#readme",
"dependencies": {
"@babel/core": "7.2.0",
"@babel/plugin-proposal-class-properties": "7.2.0",
"@babel/plugin-proposal-decorators": "7.2.0",
"@babel/plugin-proposal-export-default-from": "7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.2.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "7.2.0",
"@babel/preset-flow": "7.0.0",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "^7.2.0",
"address": "^1.0.1",
"autoprefixer": "^9.4.3",
"babel-loader": "8.0.4",
"babel-merge": "^3.0.0",
"babel-plugin-transform-jsx-class": "^0.1.2",
"babel-plugin-transform-jsx-condition": "^0.1.0",
"babel-plugin-transform-jsx-fragment": "^0.1.1",
"babel-plugin-transform-jsx-list": "^0.1.0",
"babel-plugin-transform-jsx-memo": "^0.1.2",
"babel-plugin-transform-jsx-slot": "^0.1.1",
"babel-plugin-transform-jsx-stylesheet": "^0.6.5",
"babel-runtime-jsx-plus": "^0.1.3",
"chalk": "^2.4.2",
"rax-plugin-app": "^0.1.0-0",
"rax-ssr-dev-server": "^2.0.0-0",
"stylesheet-loader": "^0.6.5",
"universal-app-shell-loader": "^0.1.1"
}
}
25 changes: 25 additions & 0 deletions packages/rax-plugin-ssr/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const SSRDevServer = require('rax-ssr-dev-server');

const getSSRBuildConfig = require('./ssr/getBuildConfig');
const getSSRDevConfig = require('./ssr/getDevConfig');
const setWebBaseConfig = require('./web/setBaseConfig');

// can‘t clone webpack chain object
module.exports = ({ chainWebpack, registerConfig, setDevServer, context }) => {
chainWebpack((config, { command }) => {
const rootDir = context.rootDir;
setWebBaseConfig(config, rootDir);

let ssrConfig;
if (command === 'build') {
ssrConfig = getSSRBuildConfig(context);
}

if (command === 'dev') {
ssrConfig = getSSRDevConfig(context);
setDevServer(SSRDevServer);
}

registerConfig('ssr', ssrConfig);
});
};
73 changes: 73 additions & 0 deletions packages/rax-plugin-ssr/src/ssr/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const chalk = require('chalk');

const disableJSXPlus = process.env.DISABLE_JSX_PLUS;

const config = {
presets: [
require.resolve('@babel/preset-flow'),
[
require.resolve('@babel/preset-env'),
{
targets: {
chrome: '49',
ios: '8'
},
loose: true,
modules: 'auto',
include: [
'transform-computed-properties'
]
}
],
[
require.resolve('@babel/preset-react'), {
'pragma': 'createElement',
'pragmaFrag': 'Fragment'
}
]
],
plugins: [
[
require.resolve('@babel/plugin-transform-runtime'),
{
'corejs': false,
'helpers': false,
'regenerator': true,
'useESModules': false
}
],
require.resolve('@babel/plugin-syntax-dynamic-import'),
// Stage 0
require.resolve('@babel/plugin-proposal-function-bind'),
// Stage 1
require.resolve('@babel/plugin-proposal-export-default-from'),
[
require.resolve('@babel/plugin-proposal-optional-chaining'),
{ loose: true },
],
[
require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
{ loose: true },
],
// Stage 2
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
require.resolve('@babel/plugin-proposal-export-namespace-from'),
// Stage 3
[
require.resolve('@babel/plugin-proposal-class-properties'),
{ loose: true },
]
]
};

if (!disableJSXPlus) {
// Enable jsx plus default.
config.plugins.push(require.resolve('babel-plugin-transform-jsx-list'));
config.plugins.push(require.resolve('babel-plugin-transform-jsx-condition'));
config.plugins.push(require.resolve('babel-plugin-transform-jsx-memo'));
config.plugins.push(require.resolve('babel-plugin-transform-jsx-slot'));
config.plugins.push([require.resolve('babel-plugin-transform-jsx-fragment'), { moduleName: 'rax' }]);
config.plugins.push(require.resolve('babel-plugin-transform-jsx-class'));
}

module.exports = config;
Loading