Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Jul 2, 2017
2 parents 9e34ea8 + 166ac4c commit c2dab34
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 108 deletions.
19 changes: 19 additions & 0 deletions .fecsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"eslint": {
"env": {
"node": true,
"browser": true
},

"globals": {
"console": true,
"require": true,
"define": true
},

"rules": {
"no-console": 0,
"fecs-no-require": "off"
}
}
}
1 change: 1 addition & 0 deletions .postcssrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module.exports = {
plugins: {

// to edit target browsers: use "browserlist" field in package.json
autoprefixer: {}
}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ npm update
# 启动开发服务器,默认打开localhost:8082/home
npm run dev

# 检查您的代码是否规范
npm run lint

# 生产环境构建
npm run build

Expand Down
5 changes: 1 addition & 4 deletions build/check-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ module.exports = function () {
}

if (warnings.length) {
console.log('');
console.log(chalk.yellow('To use this template, you must update following to modules:'));
console.log();
console.log(chalk.yellow('\nTo use this template, you must update following to modules:\n'));

warnings.forEach(function (warning) {
console.log(' ' + warning);
});

console.log();
process.exit(1);
}
};
3 changes: 2 additions & 1 deletion build/dev-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

'use strict';

require('eventsource-polyfill');
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true');
const hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true');

hotClient.subscribe(function (event) {
if (event.action === 'reload') {
Expand Down
24 changes: 11 additions & 13 deletions build/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ const proxyMiddleware = require('http-proxy-middleware');
const webpackConfig = require('./webpack.dev.conf');
const utils = require('./utils');

// default port where dev server listens for incoming traffic
// 默认调试服务器端口
let port = process.env.PORT || config.dev.port;

// automatically open browser, if not set will be false
// 启动调试服务器时是否自动打开浏览器,默认为 false
let autoOpenBrowser = !!config.dev.autoOpenBrowser;

// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
let proxyTable = config.dev.proxyTable;

let app = express();
let compiler = webpack(webpackConfig);

Expand All @@ -44,7 +40,7 @@ let hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: function () {}
});

// force page reload when html-webpack-plugin template changes
// html-webpack-plugin 的模版文件更新的时候,强制重新刷新调试页面
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
hotMiddleware.publish({
Expand All @@ -54,7 +50,10 @@ compiler.plugin('compilation', function (compilation) {
});
});

// proxy api requests
// 指定需要代理的请求列表
let proxyTable = config.dev.proxyTable;

// 代理请求
Object.keys(proxyTable).forEach(function (context) {
let options = proxyTable[context];
if (typeof options === 'string') {
Expand All @@ -79,14 +78,13 @@ app.use(require('connect-history-api-fallback')({
rewrites: rewrites
}));

// serve webpack bundle output
// 服务器部署 webpack 打包的静态资源
app.use(devMiddleware);

// enable hot-reload and state-preserving
// compilation error display
// 使用热更新, 如果编译出现错误会实时展示编译错误
app.use(hotMiddleware);

// serve pure static assets
// 纯静态资源服务
let staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory);
app.use(staticPath, express.static('./static'));

Expand All @@ -102,7 +100,7 @@ console.log('> Starting dev server...');
devMiddleware.waitUntilValid(function () {
console.log('> Listening at ' + uri + '\n');

// when env is testing, don't need open it
// 当测试环境下,不需要打开浏览器
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri);
}
Expand Down
31 changes: 16 additions & 15 deletions build/multipage-plugin.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable */

// TODO: 在pr通过之前,先使用
'use strict';

var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var TemplatedPathPlugin = require("webpack/lib/TemplatedPathPlugin");
var path = require("path");
var TEMPLATED_PATH_REGEXP_NAME = /\[name\]/gi;
// TODO: 在 pr 通过之前,先使用
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TemplatedPathPlugin = require("webpack/lib/TemplatedPathPlugin");
const path = require("path");
const TEMPLATED_PATH_REGEXP_NAME = /\[name\]/gi;

function setPluginOptions (pluginOptions) {
return {
Expand All @@ -25,25 +26,25 @@ function MultipageWebpackPlugin(pluginOptions) {
Object.assign(this, setPluginOptions(pluginOptions || {}));
}

MultipageWebpackPlugin.prototype.getFullTemplatePath = function(entryKey) {
var appliedTemplatedPath = this.templatePath;
var appliedTemplatedFilename = this.templateFilename;
MultipageWebpackPlugin.prototype.getFullTemplatePath = function (entryKey) {
let appliedTemplatedPath = this.templatePath;
let appliedTemplatedFilename = this.templateFilename;
appliedTemplatedPath = appliedTemplatedPath.replace(TEMPLATED_PATH_REGEXP_NAME, entryKey);
appliedTemplatedFilename = appliedTemplatedFilename.replace(TEMPLATED_PATH_REGEXP_NAME, entryKey);

return path.join(appliedTemplatedPath, appliedTemplatedFilename);
}

MultipageWebpackPlugin.prototype.apply = function(compiler) {
var self = this;
var webpackConfigOptions = compiler.options;
var entriesToCreateTemplatesFor = Object.keys(webpackConfigOptions.entry)
let self = this;
let webpackConfigOptions = compiler.options;
let entriesToCreateTemplatesFor = Object.keys(webpackConfigOptions.entry)
.filter(function (entry) {
return entry !== this.vendorChunkName;
return entry !== self.vendorChunkName;
});

entriesToCreateTemplatesFor.forEach(function (entryKey) {
var htmlWebpackPluginOptions = {
let htmlWebpackPluginOptions = {
filename: self.getFullTemplatePath(entryKey),
chunksSortMode: 'dependency',
chunks: ['inline', self.vendorChunkName, entryKey, self.sharedChunkName]
Expand All @@ -63,7 +64,7 @@ MultipageWebpackPlugin.prototype.apply = function(compiler) {
name: "shared",
minChunks: entriesToCreateTemplatesFor.length || 3,
chunks: Object.keys(webpackConfigOptions.entry)
}),
}),
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: Infinity,
Expand Down
1 change: 0 additions & 1 deletion build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

/* eslint-disable no-console */
'use strict';

const fs = require('fs');
Expand Down
8 changes: 5 additions & 3 deletions build/vue-loader.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

'use strict';

var utils = require('./utils');
var config = require('../config');
var isProduction = process.env.NODE_ENV === 'production';
const utils = require('./utils');
const config = require('../config');
const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
loaders: utils.cssLoaders({
sourceMap: isProduction
? config.build.productionSourceMap
: config.dev.cssSourceMap,

// extract: isProduction
extract: true
})
Expand Down
10 changes: 5 additions & 5 deletions build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

/* eslint-disable no-console */
'use strict';

var path = require('path');
var utils = require('./utils');
var config = require('../config');
var vueLoaderConfig = require('./vue-loader.conf');
const path = require('path');
const utils = require('./utils');
const config = require('../config');
const vueLoaderConfig = require('./vue-loader.conf');

function resolve(dir) {
return path.join(__dirname, '..', dir);
Expand Down
2 changes: 1 addition & 1 deletion build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

/* eslint-disable no-console */
'use strict';

const path = require('path');
const utils = require('./utils');
Expand Down
40 changes: 21 additions & 19 deletions build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

/* eslint-disable no-console */

var path = require('path');
var utils = require('./utils');
var webpack = require('webpack');
var config = require('../config');
var merge = require('webpack-merge');
var baseWebpackConfig = require('./webpack.base.conf');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
var SkeletonWebpackPlugin = require('vue-skeleton-webpack-plugin');
var SwRegisterWebpackPlugin = require('sw-register-webpack-plugin');
var WebpackCdnPlugin = require('webpack-cdn-plugin');
'use strict';

const path = require('path');
const utils = require('./utils');
const webpack = require('webpack');
const config = require('../config');
const merge = require('webpack-merge');
const baseWebpackConfig = require('./webpack.base.conf');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const SkeletonWebpackPlugin = require('vue-skeleton-webpack-plugin');
const SwRegisterWebpackPlugin = require('sw-register-webpack-plugin');
const WebpackCdnPlugin = require('webpack-cdn-plugin');
const MultipageWebpackPlugin = require('./multipage-plugin');

var env = process.env.NODE_ENV === 'testing'
let env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: config.build.env;

function resolve(dir) {
return path.join(__dirname, '..', dir);
}

var webpackConfig = merge(baseWebpackConfig, {
let webpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
Expand All @@ -46,6 +46,7 @@ var webpackConfig = merge(baseWebpackConfig, {
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
plugins: [

// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env
Expand Down Expand Up @@ -124,7 +125,7 @@ var webpackConfig = merge(baseWebpackConfig, {
});

if (config.build.productionGzip) {
var CompressionWebpackPlugin = require('compression-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');

webpackConfig.plugins.push(
new CompressionWebpackPlugin({
Expand All @@ -142,7 +143,8 @@ if (config.build.productionGzip) {
}

if (config.build.bundleAnalyzerReport) {
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}

Expand Down
18 changes: 10 additions & 8 deletions build/webpack.skeleton.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

/* eslint-disable no-console */
'use strict';

var webpack = require('webpack');
var config = require('../config');
var merge = require('webpack-merge');
var baseWebpackConfig = require('./webpack.base.conf');
var nodeExternals = require('webpack-node-externals');
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
var utils = require('./utils');
const webpack = require('webpack');
const config = require('../config');
const merge = require('webpack-merge');
const baseWebpackConfig = require('./webpack.base.conf');
const nodeExternals = require('webpack-node-externals');
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
const utils = require('./utils');

module.exports = merge(baseWebpackConfig, {
target: 'node',
Expand All @@ -21,13 +21,15 @@ module.exports = merge(baseWebpackConfig, {
libraryTarget: 'commonjs2'
}),
externals: nodeExternals({

// do not externalize CSS files in case we need to import it from a dep
whitelist: /\.css$/
}),
plugins: [
new webpack.DefinePlugin({
'process.env': config.build.env
}),

// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
new OptimizeCSSPlugin({
Expand Down
7 changes: 6 additions & 1 deletion config/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
* @author *__ author __*{% if: *__ email __* %}(*__ email __*){% /if %}
*/

var path = require('path');
'use strict';

const path = require('path');

module.exports = {

// 前缀
prefix: 'svg-',

// 用户自定义的svg文件夹
svgDir: path.resolve(__dirname, '../src/assets/svg')

// ,
// 项目中使用的fontawesome名
// icons: [
Expand Down
Loading

0 comments on commit c2dab34

Please sign in to comment.