我有一個問題,當我安裝整個Maven模塊時,Maven + frontend-maven-plugin和webpack不能很好地協作;簡單地說的WebPack的htmlwebpackPlugin不會注入捆綁JS/CSS文件,我第一次安裝一個Maven模塊,出於某種原因,即使模板這樣提供:htmlwebpackPlugin + Maven - 我如何手動注入捆綁的chunkhash文件?
new HtmlWebpackPlugin({
template : '../resources/public/index.html',
filename : 'index.html',
inject : 'body',
})
但是如果我手動運行frontend-maven-plugin
在安裝整個Maven模塊之後,它實際上會注入正確的文件,這是非常奇怪的行爲。
爲了解決這個問題,我想知道是否有一種手動方式來以某種方式在我自己的index.html
模板中注入這些捆綁文件(我只有三個; 1個css,2個js文件)和chunkhash?這會使構建更加一致。
我的webpack.config.js
的片段 - 正如您所看到的,如果我們不在開發中,我們會將chunkhash添加到文件名。
"use strict";
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
let path = require('path');
let webpack = require("webpack");
const PATHS = {
build: path.join(__dirname, '../../../target', 'classes', 'public'),
};
const env = process.env.NODE_ENV;
let isDev = false;
if(env == "dev"){
isDev = true;
}
console.log(`Dev environment: ${isDev}`);
module.exports = {
entry: {
main: './js/index.jsx',
vendor: [
"react","react-dom","axios",
"react-table", "mobx", "mobx-react", "mobx-utils", "lodash"],
},
output: {
path: PATHS.build,
filename: `bundle.${isDev ? '' : '[chunkhash]'}.js`
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({name: "vendor", filename: `/static/js/vendor.bundle.${isDev ? '' : '[chunkhash]'}.js`}),
new ExtractTextPlugin(`/static/css/[name].${isDev ? '' : '[chunkhash]'}.css`),
new HtmlWebpackPlugin({
template : '../resources/public/index.html',
filename : 'index.html',
inject : 'body',
})
],
module: {
loaders: [
// Bunch of loaders
]
},
};