I try to create a dummy project to test Webpack + Angular + TypeScript, but i don't find anyway to get ng-include works.
My project "structure" (it's really a dummy project) :
/src/
58852927.jpg
App.ts
index.html
style.scss
test.html
Test.ts
/typings/ ...
/webpack.config.js
My index.html file :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="app">
<div class="toto">
RedRed
<span class="fa fa-check"></span>
</div>
<div>
<ng-include src="'test.html'"></ng-include>
</div>
<img src="58852927.jpg" alt="">
<img src="58852927.jpg" alt="">
<img src="58852927.jpg" alt="">
</body>
</html>
(I try with /test.html, ./test.html)
My App.ts (entry point of my app) :
import "./style.scss"
import "./test.html"
import angular = require("angular");
import {toto} from "./Test"
angular
.module("app", [])
.run(function () {
angular.element(".toto").text(toto);
});
And my webpack.config :
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpack = require("webpack");
module.exports = {
entry: ['webpack/hot/dev-server', "./src/App.ts"],
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
module: {
loaders: [
{
test: /\.ts$/,
loader: "ts-loader"
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.scss$/,
loader: "style-loader!css-loader?sourceMap!sass-loader?sourceMap"
},
{
test: /\.html$/,
loader: "html"
},
{
test: /\.html$/,
exclude:/index\.html$/, //I don't want to put index in templateCache
loader: "ngtemplate!html"
},
{
test: /\.(jpg|png|gif)$/,
loader: "file-loader?name=assets/[name].[ext]"
},
{
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
loader: 'url-loader'
},
{
test: require.resolve("jquery"),
loader: 'expose?jQuery'
},
{
test: require.resolve("angular"),
loader: "imports?jQuery=jquery"
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: "Lab",
filename: "index.html",
template: "./src/index.html"
})
]
};
And anytime I refresh the browser, i got a
GET http://localhost:9780/test.html 404 (Not Found)
I try to use the webpack-require-plugin as i saw here : Webpack: using require for ng-include
I try to replace ngtemplate with ng-cache-loader : https://github.com/teux/ng-cache-loader
I don't have any more ideas...