From f65fa24bb56e8a0b092d93bde63bac3f563bbd94 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Fri, 4 Aug 2017 17:55:02 +0800 Subject: [PATCH 1/2] support config.hash --- src/config/webpack.config.dev.js | 6 ++++++ src/config/webpack.config.prod.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/config/webpack.config.dev.js b/src/config/webpack.config.dev.js index 7d4ff33..091b059 100644 --- a/src/config/webpack.config.dev.js +++ b/src/config/webpack.config.dev.js @@ -43,6 +43,12 @@ export default function (config, cwd) { 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 dllPlugins = config.dllPlugin ? [ 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 = { From 0fa83b746acfb228eea31bfe399eddf924a75342 Mon Sep 17 00:00:00 2001 From: sorrycc Date: Mon, 7 Aug 2017 11:06:38 +0800 Subject: [PATCH 2/2] support html-webpack-plugin --- package.json | 1 + src/config/common.js | 10 +++++++++- src/config/webpack.config.dev.js | 6 ------ test/fixtures/build/html-webpack-plugin/.roadhogrc | 3 +++ .../fixtures/build/html-webpack-plugin/package.json | 1 + .../build/html-webpack-plugin/src/index.ejs | 13 +++++++++++++ .../fixtures/build/html-webpack-plugin/src/index.js | 1 + 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/build/html-webpack-plugin/.roadhogrc create mode 100644 test/fixtures/build/html-webpack-plugin/package.json create mode 100644 test/fixtures/build/html-webpack-plugin/src/index.ejs create mode 100644 test/fixtures/build/html-webpack-plugin/src/index.js 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.dev.js b/src/config/webpack.config.dev.js index 091b059..7d4ff33 100644 --- a/src/config/webpack.config.dev.js +++ b/src/config/webpack.config.dev.js @@ -43,12 +43,6 @@ export default function (config, cwd) { 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 dllPlugins = config.dllPlugin ? [ 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 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/test/fixtures/build/html-webpack-plugin/src/index.js b/test/fixtures/build/html-webpack-plugin/src/index.js new file mode 100644 index 0000000..9658cc6 --- /dev/null +++ b/test/fixtures/build/html-webpack-plugin/src/index.js @@ -0,0 +1 @@ +alert(1);