Answer the question
In order to leave comments, you need to log in
How to properly organize the assembly of the Angular project, as well as the inclusion of files?
I am currently learning webpack.
Created a test angular application (SPA)...
Everything seems to move, compile and run.
But in the process of stamping new controllers, I thought a little about the fact that the assembled file grows by leaps and bounds, but depending on the number of
stamped goodies
...
states that connect the desired controller and template
import mainController from './app/main/components/main.component.js';
import mainTemplate from './components/navbar/navbar.pug';
// some code
$stateProvider.state('/', {
url: '/', // root route
template: mainTemplate,
controller: mainController
});
app.js
, files angular
are placed in a separate filevendor
config.entry = {
app: './src/app.js',
vendor: [
'angular',
'angular-ui-router'
]
};
config.output = {
path: path.join(__dirname, '/.tmp/'),
filename: '[name].entry.js',
publicPath: `/`,
chunkFilename: '[name].commons.js'
};
babel
. Templates are written in pug
(former jade
), also for the purpose of study. I use Sass
a preprocessor, styles are pulled from js
files and stored separately.config.module = {
loaders: [
// JS loader
// Reference: https://github.com/babel/babel-loader
{
test: /\.js$/,
loader: 'babel',
include: [
path.resolve(__dirname, 'src/')
]
},
// Images loader
{
test: /\.(png|jpg|jpeg|gif|svg)([\?]?.*)$/,
loader: 'file?name=./assets/images/[name].[ext]'
},
// Fonts loader
{
test: /\.(woff|woff2|ttf|eot)([\?]?.*)$/,
loader: 'file?name=./assets/fonts/[name].[ext]'
},
// Pug HTML loader
{
test: /\.pug$/,
loader: 'pug-html',
query: {
// Allow to use attrs without values
// Issue: https://github.com/pugjs/pug/issues/1180
doctype: 'html'
}
},
// Sass loader
{
test: /\.(scss|sass)$/,
loader: extractTextPlugin.extract('style', ['css?sourceMap', 'sass?sourceMap'])
}
],
// Adds and removes AngularJS dependency injection annotations
// Reference: https://github.com/olov/ng-annotate
postLoaders: [{
test: /\.js$/,
loader: 'ng-annotate?single_quotes'
}]
};
app.entry.js
does not swell, because, in my opinion, it is not very good that all project files are added to it. This is what happens. The user went to the site, only the main one opened for him, but anyway he downloads app.entry.js
, in which the code is not only for the main one, but also, let's say, for a personal account, product page, product card, gallery there ... Not good after all. Answer the question
In order to leave comments, you need to log in
Google something like: webpack lazyload with the addition of angularjs and other words. Here are a few links that we found:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question