Skip to content

Commit

Permalink
feat: add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
deot committed Aug 27, 2020
1 parent 0e050b4 commit 2d07102
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/client/static/index.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<% if(!htmlWebpackPlugin.options.__DEV__) { %>
<% if(!htmlWebpackPlugin.options.useExternal) { %>
<script src="//unpkg.com/vue@2.6.11/dist/vue.min.js"></script>
<script src="//unpkg.com/lodash@4.17.15/lodash.min.js"></script>
<script src="//unpkg.com/@babel/polyfill@7/browser.js"></script>
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program
.option('-p, --port <port>', 'server port (default: 8080)')
.option('--host <host>', 'server host (default: 0.0.0.0)')
.option('--config <config file>', 'config options file')
.option('--debug', 'debug mode')
.action((sourceDir = '.', commandOptions) => {
let app = new App({
sourceDir: resolve(sourceDir),
Expand Down
22 changes: 10 additions & 12 deletions packages/cli/src/node/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ class Config {
*/
generateDefault() {
let { port, host } = this.$parent;
const { docConfig = {}, sourceDir, browserDir } = this.$parent.$parent;
const { docConfig = {}, sourceDir, browserDir, options } = this.$parent.$parent;
const { webpackConfig, runtime, locales, layout, externalResources, } = docConfig || {};
const { __DOC_MD_DIR__: baseMDDir, __DOC_SITE_DIR__, __DOC_VERSION__ } = runtime.define || {};
const { devServer, ...override } = webpackConfig || {};
const ENV_IS_DEV = process.env.NODE_ENV === 'development';
const useExternals = options.debug || !ENV_IS_DEV || undefined;

let __DEP_VC__ = false;
if (
Expand Down Expand Up @@ -178,14 +179,11 @@ class Config {
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
__DEV__: ENV_IS_DEV,
// TODO: 是否考虑针对dev也开放
externalResources: ENV_IS_DEV
? ''
: externalResources || [
'//unpkg.com/@wya/vc/lib/vc.min.css',
'//unpkg.com/@wya/vc/lib/vc.min.js'
],
useExternals,
externalResources: (useExternals && externalResources) || [
'//unpkg.com/@wya/vc/lib/vc.min.css',
'//unpkg.com/@wya/vc/lib/vc.min.js'
],
template: resolveClient('static/index.tpl.html'),
inject: 'body',
filename: './index.html',
Expand All @@ -210,14 +208,14 @@ class Config {
: `'/'`
})
],
externals: ENV_IS_DEV
? {}
: {
externals: useExternals && (
{
vue: 'Vue',
lodash: '_',
'@babel/standalone': 'Babel',
'@wya/vc': 'WYA_VC',
}
)
};

return merge(defaultOptions, override, noOverrideConfig);
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ module.exports = class App {

async dev() {
process.env.NODE_ENV = 'development';
this.isProd = false;

await this.process();
this.devProcess = new DevProcess(this);
await this.devProcess.process();
Expand All @@ -87,8 +85,6 @@ module.exports = class App {

async build() {
process.env.NODE_ENV = 'production';
this.isProd = true;

await this.process();

this.buildProcess = new BuildProcess(this);
Expand Down
3 changes: 1 addition & 2 deletions packages/playground/src/popup/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/selection/active-line.js';
import 'codemirror/theme/material.css';
import 'codemirror/lib/codemirror.css';
import Portal from '@wya/vc/lib/portal';
import Transition from '@wya/vc/lib/transition';
import { Portal, Transition } from '@wya/vc';
import { Drag } from '@wya/doc-utils';
const wrapperComponent = {
Expand Down

0 comments on commit 2d07102

Please sign in to comment.