Using webpack I extracted the source files from the distribution files.
One problem I am facing is related to output.publicPath, if I define it, the generated index.html has the wrong path to CSS and JS resources. I think the problem is related to extract-text-webpack-pluginSee: https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/246
Now that I have split the code into source and distribution, mine index.htmlis available at http://localhost/target/classes/war. And to refresh each page, you need to enter the URL manually because the routes did not recognize the folder name. The tag <base />in the head does not seem to have an effect.
How can I instruct webpack to display the contents of a folder ./target/classes/waron http://localhost/? (without use output.publicPath)
For completeness, we find below everything webpack.config.jsin its current form:
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var GoogleFontsPlugin = require("google-fonts-webpack-plugin");
module.exports = {
entry: {
polyfills: './src/main/webapp/polyfills.ts',
vendor: './src/main/webapp/vendor.ts',
app: './src/main/webapp/app/core/global/main/main.ts'
},
output: {
filename: 'target/classes/war/script/[name].[hash].bundle.js'
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
css: path.resolve(__dirname, "src/main/webapp/WEB-INF/scss"),
src: path.resolve(__dirname, "src/main/webapp"),
dist: path.resolve(__dirname, "target/class/war")
}
},
module: {
rules: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
options: {
configFileName: path.resolve(__dirname, "src/main/webapp/WEB-INF/conf/tsconfig.json")
}
},
'angular2-template-loader'
]
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loaders: [
{
loader: "file-loader",
options: {
hash: "sha512",
digest: "hex",
name: "/target/classes/war/assets/[name].[hash].[ext]"
}
}
]
},
{
test: /\.(css|scss)$/,
exclude: path.resolve(__dirname, "src/main/webapp/scss"),
include: path.resolve(__dirname, "src/main/webapp/app"),
loaders: [
{
loader: "raw-loader"
},
{
loader: "sass-loader"
}
]
},
{
test: /\.(css|scss)$/,
exclude: path.resolve(__dirname, "src/main/webapp/app"),
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "resolve-url-loader"
},
{
loader: "sass-loader"
}
]
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.resolve(__dirname, "src/main/webapp"),
{}
),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/main/webapp/index.html',
filename: 'target/classes/war/index.html',
chunksSortMode: function (chunk1, chunk2) {
var order = ['polyfills', 'vendor', 'app'];
var order1 = order.indexOf(chunk1.names[0]);
var order2 = order.indexOf(chunk2.names[0]);
return order1 - order2;
}
}),
new ExtractTextPlugin({
filename: "target/classes/war/css/styles.[contenthash].css"
}),
new GoogleFontsPlugin({
fonts: [
{family: "Lato"}
],
path: "src/main/webapp/scss/fonts/",
filename: "src/main/webapp/scss/fonts/fonts.css"
})
]
};