The idea is to have 1 JS file out of all html files. and after just to use it via require:
templateUrl: require('./views/user-list.html')
Could you share you experience please? I was googling for it and found several loaders for webpack but not sure what to use.
In order to use a custom webpack config, you will need to add @angular-builders/custom-webpack and @angular-builders/dev-server to your project as devDependency packages: npm install --save-dev @angular-builders/custom-webpack @10.0.
Webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API. If you're still new to webpack, please read through the core concepts and this comparison to learn why you might use it over the other tools that are out in the community.
The application builder uses the webpack build tool, with default configuration options specified in the workspace configuration file ( angular.json ) or with a named alternative configuration.
There are some alternatives to Webpack that provide the same functionality as webpack. These alternatives are gulp, babel, parcel, browserify, grunt, npm, and requireJS.
I decided to use ng-cache loader for webpack together with ES2015 syntax: it means import from
instead of require
.
Part of my webpack config:
module: {
loaders: [
{ test: /\.js$/, loader: 'babel', include: APP },
{ test: /\.html$/, loader: 'ng-cache?prefix=[dir]/[dir]' },
]
},
and example of directive with template:
import avatarTemplate from './views/avatar.html';
const avatar = function() {
return {
restrict: 'E',
replace: true,
scope: {
user: '='
},
template: avatarTemplate
}
};
export default avatar;
your answer is right. However just offering alternative for it:
const avatar = function() {
return {
restrict: 'E',
replace: true,
scope: {
user: '='
},
template: require("../path/to/file.html"),
}
};
export default avatar;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With