diff --git a/.gitignore b/.gitignore index 233eb3c8..5aeb92b3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ node_modules /dist /lib /public +/gh-pages /.vscode /output /toolkit/amis-renderer diff --git a/.npmignore b/.npmignore index 66876c4c..5f8f4168 100644 --- a/.npmignore +++ b/.npmignore @@ -14,4 +14,5 @@ fis-conf.js /__tests__ /__mocks__ /coverage -/publish.sh \ No newline at end of file +/publish.sh +/gh-pages \ No newline at end of file diff --git a/examples/components/App.jsx b/examples/components/App.jsx index 416498a2..c3fadda0 100644 --- a/examples/components/App.jsx +++ b/examples/components/App.jsx @@ -6,7 +6,7 @@ import {AlertComponent, ToastComponent} from '../../src/components/index'; import { mapTree } from '../../src/utils/helper'; -import { Router, Route, IndexRoute, browserHistory, Link, Redirect } from 'react-router'; +import { Router, Route, IndexRoute, browserHistory, hashHistory, Link, Redirect } from 'react-router'; import makeSchemaRenderer from './SchemaRender'; @@ -712,9 +712,14 @@ export class App extends React.PureComponent { export default function entry({pathPrefix}) { PathPrefix = pathPrefix || '/examples'; + let history = browserHistory; + + if (process.env.NODE_ENV === 'production') { + history = hashHistory; + } return ( - + {navigations2route(PathPrefix)} diff --git a/fis-conf.js b/fis-conf.js index e3d55498..a1a17fe3 100644 --- a/fis-conf.js +++ b/fis-conf.js @@ -5,6 +5,7 @@ const path = require('path'); const parserMarkdown = require('./build/md-parser'); fis.get('project.ignore').push( 'public/**', + 'gh-pages/**', '.*/**' ); @@ -225,4 +226,128 @@ if (fis.project.currentMedia() === 'publish') { }); // publishEnv.unhook('node_modules'); publishEnv.hook('relative'); +} else if (fis.project.currentMedia() === 'gh-pages') { + const ghPages = fis.media('gh-pages'); + + ghPages.match('/node_modules/(**)', { + release: '/n/$1' + }); + + ghPages.match('/examples/(**)', { + release: '/$1' + }); + + ghPages.match('/{examples,docs}/**', { + preprocessor: function(contents, file) { + if (!file.isText() || typeof contents !== 'string') { + return contents; + } + + return contents.replace(/(\\?(?:'|"))\/api\/mock2?\//g, function(_, qutoa) { + return qutoa + 'https://houtai.baidu.com/api/mock2/'; + }); + } + }) + + ghPages.match('mock/**.{json,js,conf}', { + release: false + }); + + ghPages.match('::package', { + packager: fis.plugin('deps-pack', { + 'pkg/npm.js': [ + '/mod.js', + 'node_modules/**.js', + '!monaco-editor/**', + '!flv.js/**', + '!hls.js/**', + '!amis/lib/editor/**', + '!froala-editor/**', + '!amis/lib/components/RichText.js', + '!jquery/**', + '!zrender/**', + '!echarts/**', + ], + 'pkg/rich-text.js': [ + 'amis/lib/components/RichText.js', + 'froala-editor/**', + 'jquery/**' + ], + 'pkg/echarts.js': [ + 'zrender/**', + 'echarts/**' + ], + 'pkg/api-mock.js': [ + 'mock/*.ts' + ], + 'pkg/app.js': [ + '/app.tsx', + '/app.tsx:deps' + ], + 'pkg/rest.js': [ + '**.{js,jsx,ts,tsx}', + '!static/mod.js', + '!monaco-editor/**', + '!echarts/**', + '!flv.js/**', + '!hls.js/**', + '!froala-editor/**', + '!jquery/**', + '!amis/lib/components/RichText.js', + '!zrender/**', + '!echarts/**', + ], + // css 打包 + 'pkg/style.css': [ + 'node_modules/*/**.css', + '*.scss', + '!/scss/*.scss', + '/scss/*.scss' + ] + }) + }); + + ghPages.match('*.{css,less,scss}', { + optimizer: fis.plugin('clean-css'), + useHash: true + }); + + ghPages.match('::image', { + useHash: true + }); + + ghPages.match('*.{js,ts,tsx}', { + optimizer: fis.plugin('uglify-js'), + useHash: true + }); + + ghPages.match('*.map', { + release: false, + url: 'null', + useHash: false + }); + ghPages.match('{*.jsx,*.tsx,*.ts}', { + moduleId: function (m, path) { + return fis.util.md5('amis' + path); + }, + parser: fis.plugin('typescript', { + sourceMap: false, + importHelpers: true + }) + }); + ghPages.match('*', { + domain: '/amis', + deploy: [ + fis.plugin('skip-packed'), + fis.plugin('local-deliver', { + to: './gh-pages' + }) + ] + }); + ghPages.match('{*.min.js,monaco-editor/**.js}', { + optimizer: null + }); + ghPages.match('monaco-editor/**.js', { + useHash: false + }); }