2017-05-30 73 views
0

我有一個問題,當我安裝整個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 
     ] 
    }, 
}; 

回答

0

我解決了這個問題 - 這個問題是基本上是Maven的/春將採取的Index.html(這是我作爲一個模板)在resources/public我的目標文件夾之外,並在目標文件夾覆蓋它 - 基本上覆蓋輸出從webpackHTMLplugin,這在這方面是合乎邏輯的。

我解決了這個問題,因爲resources/public中沒有任何index.html文件,但在webpack所在的src文件夾中只有template.html。因此,Maven/Spring不會用空模板覆蓋輸出。

相關問題