From 2cafe15e854b493d335652755b74674c7e2da4f6 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 12 Oct 2016 17:15:59 +0800 Subject: [PATCH] Enable production assets hash --- .gitignore | 1 + package.json | 3 ++ public/views/foot.ejs | 3 +- public/views/head.ejs | 2 +- public/views/includes/header.ejs | 3 ++ public/views/includes/scripts.ejs | 3 ++ public/views/index.ejs | 4 +-- public/views/pretty.ejs | 5 ++- public/views/slide.ejs | 4 +-- webpack.production.js | 58 ++++++++++++++++++++++++++++++- 10 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 public/views/includes/header.ejs create mode 100644 public/views/includes/scripts.ejs diff --git a/.gitignore b/.gitignore index 29f916f0..9a95231c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ public/js/config.js # ignore webpack build public/build +public/views/build diff --git a/package.json b/package.json index 5ba9101f..03333fb8 100644 --- a/package.json +++ b/package.json @@ -122,13 +122,16 @@ "url": "https://github.com/hackmdio/hackmd.git" }, "devDependencies": { + "babel-core": "^6.17.0", "babel-loader": "^6.2.5", "bower-webpack-plugin": "^0.1.9", "css-loader": "^0.25.0", + "ejs-loader": "^0.3.0", "exports-loader": "^0.6.3", "expose-loader": "^0.7.1", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.9.0", + "html-webpack-plugin": "^2.22.0", "imports-loader": "^0.6.5", "json-loader": "^0.5.4", "less": "^2.7.1", diff --git a/public/views/foot.ejs b/public/views/foot.ejs index 0ce4b85b..abf2da12 100644 --- a/public/views/foot.ejs +++ b/public/views/foot.ejs @@ -20,9 +20,8 @@ <% } %> - - +<%- include build/index-scripts %> diff --git a/public/views/head.ejs b/public/views/head.ejs index 72434892..f4ba108a 100644 --- a/public/views/head.ejs +++ b/public/views/head.ejs @@ -36,7 +36,7 @@ - +<%- include build/index-header %> diff --git a/public/views/includes/header.ejs b/public/views/includes/header.ejs new file mode 100644 index 00000000..89f3a0d1 --- /dev/null +++ b/public/views/includes/header.ejs @@ -0,0 +1,3 @@ +<% for (var css in htmlWebpackPlugin.files.css) { %> + +<% } %> diff --git a/public/views/includes/scripts.ejs b/public/views/includes/scripts.ejs new file mode 100644 index 00000000..4eec75e8 --- /dev/null +++ b/public/views/includes/scripts.ejs @@ -0,0 +1,3 @@ +<% for (var chunk in htmlWebpackPlugin.files.chunks) { %> + +<% } %> diff --git a/public/views/index.ejs b/public/views/index.ejs index f24a039e..0e41db57 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -27,6 +27,7 @@ + <%- include build/cover-header %> @@ -193,7 +194,6 @@ - <% if(useCDN) { %> @@ -205,7 +205,7 @@ <% } %> - + <%- include build/cover-scripts %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index 6f7c4e72..e617383c 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -35,6 +35,7 @@ + <%- include build/pretty-header %> @@ -97,13 +98,11 @@ <% } else { %> - <% } %> +<%- include build/pretty-scripts %> - - <%- include ga %> diff --git a/public/views/slide.ejs b/public/views/slide.ejs index c463f378..f959a346 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -39,6 +39,7 @@ + <%- include build/slide-header %> <% } else { %> - @@ -103,7 +103,7 @@ <% } %> - + <%- include build/slide-scripts %> diff --git a/webpack.production.js b/webpack.production.js index ce8dd27e..173ca0cd 100644 --- a/webpack.production.js +++ b/webpack.production.js @@ -1,6 +1,8 @@ var baseConfig = require('./webpackBaseConfig'); var webpack = require('webpack'); var ExtractTextPlugin = require("extract-text-webpack-plugin"); +var path = require('path'); +var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = Object.assign({}, baseConfig, { plugins: [ @@ -19,6 +21,54 @@ module.exports = Object.assign({}, baseConfig, { filename: '[name].js', minChunks: Infinity }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/header.ejs', + chunks: ['vendor', 'index'], + filename: path.join(__dirname, 'public/views/build/index-header.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/scripts.ejs', + chunks: ['vendor', 'index'], + filename: path.join(__dirname, 'public/views/build/index-scripts.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/header.ejs', + chunks: ['vendor', 'locale'], + filename: path.join(__dirname, 'public/views/build/cover-header.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/scripts.ejs', + chunks: ['vendor', 'locale'], + filename: path.join(__dirname, 'public/views/build/cover-scripts.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/header.ejs', + chunks: ['vendor', 'public'], + filename: path.join(__dirname, 'public/views/build/pretty-header.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/scripts.ejs', + chunks: ['vendor', 'public'], + filename: path.join(__dirname, 'public/views/build/pretty-scripts.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/header.ejs', + chunks: ['vendor', 'slide'], + filename: path.join(__dirname, 'public/views/build/slide-header.ejs'), + inject: false + }), + new HtmlWebpackPlugin({ + template: 'public/views/includes/scripts.ejs', + chunks: ['vendor', 'slide'], + filename: path.join(__dirname, 'public/views/build/slide-scripts.ejs'), + inject: false + }), new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('production') @@ -30,5 +80,11 @@ module.exports = Object.assign({}, baseConfig, { }, sourceMap: false }) - ] + ], + + output: { + path: path.join(__dirname, 'public/build'), + publicPath: '/build/', + filename: '[id].[name].[hash].js' + }, });