From c0222c3957005d8c0ed886740ea46382f7fceb56 Mon Sep 17 00:00:00 2001 From: zuiidea Date: Fri, 28 Jul 2017 19:26:05 +0800 Subject: [PATCH] add version build --- .roadhogrc.js | 59 ++++++++++++++++++++++++++--------------------- package.json | 5 ++++ webpack.config.js | 33 +++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/.roadhogrc.js b/.roadhogrc.js index 2de5f1e..d88e232 100644 --- a/.roadhogrc.js +++ b/.roadhogrc.js @@ -1,14 +1,17 @@ const path = require('path') +const { version } = require('./package.json') const svgSpriteDirs = [ path.resolve(__dirname, 'src/svg/'), - require.resolve('antd').replace(/index\.js$/, ''), + require.resolve('antd').replace(/index\.js$/, '') ] export default { - entry: 'src/index.js', - svgSpriteLoaderDirs: svgSpriteDirs, - "theme": "./theme.config.js", + entry : 'src/index.js', + svgSpriteLoaderDirs : svgSpriteDirs, + theme : "./theme.config.js", + publicPath : `/${version}/`, + outputPath : `./dist/${version}/`, // 接口代理示例 // "proxy": { // "/api/v1": { @@ -22,29 +25,33 @@ export default { // "pathRewrite": { "^/api/v2" : "/api/v2" } // } // }, - "env": { - "development": { - "extraBabelPlugins": [ - "dva-hmr", - "transform-runtime", - ["import", { "libraryName": "antd", "style": true }] + env : { + development: { + extraBabelPlugins: [ + "dva-hmr", + "transform-runtime", + [ + "import", { + "libraryName": "antd", + "style": true + } ] - }, - "production": { - "extraBabelPlugins": [ - "transform-runtime", - ["import", { "libraryName": "antd", "style": true}] + ] + }, + production: { + extraBabelPlugins: [ + "transform-runtime", + [ + "import", { + "libraryName": "antd", + "style": true + } ] - } + ] + } }, - "dllPlugin": { - "exclude": [ - "babel-runtime" - ], - "include": [ - "dva/router", - "dva/saga", - "dva/fetch", - ] - } + dllPlugin : { + exclude: ["babel-runtime"], + include: ["dva/router", "dva/saga", "dva/fetch"] + } } diff --git a/package.json b/package.json index c60f0c4..4dadd1e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,7 @@ { "private": true, + "name": "antd-admin", + "version": "4.3.0", "dependencies": { "antd": "^2.11.2", "axios": "^0.16.2", @@ -9,6 +11,7 @@ "draftjs-to-markdown": "^0.4.0", "dva": "^1.2.0", "dva-loading": "^0.2.0", + "ejs-loader": "^0.3.0", "jsonp": "^0.2.1", "less-vars-to-js": "^1.1.2", "lodash": "^4.17.4", @@ -41,6 +44,8 @@ "eslint-plugin-import": "^2.6.1", "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.1.0", + "html-webpack-plugin": "^2.29.0", + "html-webpack-template": "^5.6.0", "redbox-react": "^1.2.10", "roadhog": "1.0.0-beta.7" }, diff --git a/webpack.config.js b/webpack.config.js index 2e2db97..b0e7bf6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ +const HtmlWebpackPlugin = require('html-webpack-plugin') +const HtmlWebpackTemplate = require('html-webpack-template') + module.exports = (webpackConfig, env) => { // FilenameHash - // https://webpack.js.org/configuration/output/#output-chunkfilename webpackConfig.output.chunkFilename = '[name].[hash].js' if (env === 'production' && webpackConfig.module) { @@ -25,6 +27,35 @@ module.exports = (webpackConfig, env) => { // loader: 'eslint', // }] + + webpackConfig.plugins = webpackConfig.plugins.concat([ + new HtmlWebpackPlugin({ + hash: true, + mobile: true, + title: 'antd-admin', + inject: false, + appMountId: 'root', + template: `!!ejs!${HtmlWebpackTemplate}`, + filename: env === 'production' ? '../index.html' : 'index.html', + minify: { + collapseWhitespace: true, + }, + scripts: env === 'production' ? null : [ + 'roadhog.dll.js', + ], + meta: [ + { + name: 'description', + content: 'A admin dashboard application demo built upon Ant Design and Dva.js', + }, + { + name: 'viewport', + content: 'width=device-width, initial-scale=1.0', + }, + ], + }), + ]) + // Alias webpackConfig.resolve.alias = { components: `${__dirname}/src/components`,