diff --git a/package.json b/package.json index 6db0c0d..1d00997 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "fs-extra": "^3.0.1", "glob": "^7.1.2", "gzip-size": "^3.0.0", + "html-webpack-plugin": "^2.30.1", "http-proxy-middleware": "^0.17.3", "is-plain-object": "^2.0.3", "istanbul": "^0.4.5", diff --git a/src/config/common.js b/src/config/common.js index f2727d0..5db3494 100644 --- a/src/config/common.js +++ b/src/config/common.js @@ -4,6 +4,7 @@ import { existsSync } from 'fs'; import { join } from 'path'; import ExtractTextPlugin from 'extract-text-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; import normalizeDefine from '../utils/normalizeDefine'; import winPath from '../utils/winPath'; @@ -65,7 +66,7 @@ export function getFirstRules({ paths, babelOptions }) { return [ { exclude: [ - /\.html$/, + /\.(html|ejs)$/, /\.(js|jsx)$/, /\.(css|less|scss)$/, /\.json$/, @@ -289,6 +290,13 @@ export function getCommonPlugins({ config, paths, appBuild, NODE_ENV }) { } ret.push(new webpack.DefinePlugin(defineObj)); + if (existsSync(join(paths.appSrc, 'index.ejs'))) { + ret.push(new HtmlWebpackPlugin({ + template: 'src/index.ejs', + inject: true, + })); + } + if (existsSync(paths.appPublic)) { ret.push(new CopyWebpackPlugin([ { diff --git a/src/config/webpack.config.prod.js b/src/config/webpack.config.prod.js index 9be34c2..28eefb1 100644 --- a/src/config/webpack.config.prod.js +++ b/src/config/webpack.config.prod.js @@ -41,6 +41,12 @@ export default function (args, appBuild, config, paths) { chunkFilename: '[name].async.js', }; + // Support hash + if (config.hash) { + output.filename = '[name].[chunkhash].js'; + output.chunkFilename = '[name].[chunkhash].async.js'; + } + if (library) output.library = library; const finalWebpackConfig = { diff --git a/test/fixtures/build/html-webpack-plugin/.roadhogrc b/test/fixtures/build/html-webpack-plugin/.roadhogrc new file mode 100644 index 0000000..9d78f90 --- /dev/null +++ b/test/fixtures/build/html-webpack-plugin/.roadhogrc @@ -0,0 +1,3 @@ +{ + "devtool": "" +} \ No newline at end of file diff --git a/test/fixtures/build/html-webpack-plugin/package.json b/test/fixtures/build/html-webpack-plugin/package.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/test/fixtures/build/html-webpack-plugin/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/fixtures/build/html-webpack-plugin/src/index.ejs b/test/fixtures/build/html-webpack-plugin/src/index.ejs new file mode 100644 index 0000000..e372ba0 --- /dev/null +++ b/test/fixtures/build/html-webpack-plugin/src/index.ejs @@ -0,0 +1,13 @@ + + +
+ + + +