Since a couples hours, I tried to apply ocLazyLoad on my personal project using Angular 1.5 and webpack 1 but I don't understand something because it's doesnot work :/
This is my webpack.config.js:
var path = require('path'),
webpack = require('webpack'),
libPath = path.join(__dirname, 'lib'),
nodeModulesPath = path.join(__dirname, 'node_modules'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ProgressBarPlugin = require('progress-bar-webpack-plugin'), // To be delete when webpack will accept the flag --progress in the devserver and not only in CMD
WatchIgnorePlugin = require('watch-ignore-webpack-plugin'),
SassLintPlugin = require('sasslint-webpack-plugin');
var cf = {
entry: {
app: path.join(libPath, 'index.js'),
vendor: ['angular', 'oclazyload']
},
devtool: 'source-map',
resolve: {
root: [path.resolve(__dirname, 'lib'), path.resolve(__dirname, 'node_modules')],
extensions: ['', '.js', '.json', '.scss']
},
debug: true,
cache: false,
module: {
loaders: [{
test: /\.json$/,
exclude: /node_modules/,
loaders: ["raw-loader"]
},{
test: /\.html$/,
exclude: /node_modules/,
loader: 'ngtemplate!html'
},{
test: /\.(jpe?g|gif|png|svg|woff|woff2|ttf|eot|wav|mp3)$/,
loader: 'file' // inline base64 URLs for <=10kb images, direct URLs for the rest
},{
test: /\.less$/,
exclude: /node_modules/,
loaders: ['style', 'css', 'less?sourceMap', 'resolve-url']
},{
test: /\.scss$|\.css$/,
exclude: /node_modules/,
loaders: ['style', 'css-loader', 'resolve-url', 'sass?sourceMap']
},{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['ng-annotate?add=true&map=true', 'babel', 'eslint-loader']
}]
},
eslint: {
configFile: './.eslintrc'
},
devServer: {
port: 3001,
https: false,
inline: true,
compress: true,
hot: true,
open: true,
noInfo: true
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.join(libPath, 'index.ejs'),
title: 'My App',
cache: false,
hash: true,
chunksSortMode: 'auto'
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.HotModuleReplacementPlugin(),
new WatchIgnorePlugin([
path.resolve( __dirname, './examples/'),
path.resolve(__dirname, './node_modules/'),
]),
new SassLintPlugin({
glob: 'lib/**/*.s?(a|c)ss',
ignorePlugins: [
'extract-text-webpack-plugin'
],
configFile: '.sass-lint.yml'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.bundle.js'
}),
new ProgressBarPlugin({format: ' build [:bar] ' + (':percent') + ' (:elapsed seconds)'})
]
};
module.exports = cf;
And my router:
import path from 'path';
import oclazyLoad from 'oclazyload';
import page1Module from './components/page1/page1.module';
export default function routes($stateProvider, $translateProvider, $compileProvider, $httpProvider, $urlRouterProvider) {
'ngInject';
$compileProvider.debugInfoEnabled(true);
$httpProvider.defaults.cache = true;
$stateProvider
.state('home', {
url: '/home',
views: {
mainView: {
component: 'home'
},
rightMenuView: {
component: 'rightMenu'
}
}
})
.state('page1', {
url: '/page1',
views: {
mainView: {
component: 'page1'
// I also tried to import the file and then write the import here but it does not work
},
rightMenuView: {
component: 'rightMenu'
}
},
resolve: {
foo: ['$q', '$ocLazyLoad', function ($q, $ocLazyLoad) {
let deferred = $q.defer();
require.ensure([], function () {
let module = page1Module;
$ocLazyLoad.load({
name: 'page1'
});
deferred.resolve(module);
});
return deferred.promise;
}]
}
})
}
And everytime I get this error:
angular.js:13920 Error: [$injector:unpr] Unknown provider: page1DirectiveProvider <- page1Directive
I'm lost I don't undertsand why my component is unknow.
I tried
Addmore, I noticed that page1Module.js, page1.scss, page1.html are in the bundle.js when loading the HOME page but is it normal ? If I lazyload, I think they have to appear only with a chunck when I ask the PAGE1 and not in my case when I'm on HOME page. I don't know if I'm clear :/
For me, I'm really near of this approach that I can find here :
https://github.com/ay13/webpack-angular-oclazyload
If the compilation of Webpack can be useful, this is a example :
Hi guys,
Since a couples hours, I tried to apply ocLazyLoad on my personal project using Angular 1.5 and webpack 1 but I don't understand something because it's doesnot work :/
This is my webpack.config.js:
And my router:
My module to lazyLoad:
And everytime I get this error: angular.js:13920 Error: [$injector:unpr] Unknown provider: page1DirectiveProvider <- page1Directive
I'm lost I don't undertsand why my component is unknow. I tried Addmore, I noticed that page1Module.js, page1.scss, page1.html are in the bundle.js when loading the HOME page but is it normal ? If I lazyload, I think they have to appear only with a chunck when I ask the PAGE1 and not in my case when I'm on HOME page. I don't know if I'm clear :/
For me, I'm really near of this approach that I can find here :
https://github.com/ay13/webpack-angular-oclazyload
If the compilation of Webpack can be useful, this is a example :
Thank you :)