8000 Add ExtractText and Html wepback plugins · packetloop/angular-webpack@fd9485c · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.

Commit fd9485c

Browse files
committed
Add ExtractText and Html wepback plugins
1 parent 052e94b commit fd9485c

File tree

4 files changed

+48
-40
lines changed

4 files changed

+48
-40
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
"css-loader": "^0.15.6",
2525
"eslint": "^1.0.0",
2626
"exports-loader": "^0.6.2",
27+
"extract-text-webpack-plugin": "^0.8.2",
2728
"file-loader": "^0.8.4",
2829
"hamlc-loader": "0.0.11",
30+
"html-webpack-plugin": "^1.6.0",
2931
"imports-loader": "^0.6.4",
3032
"isparta-loader": "^0.2.0",
3133
"jasmine-core": "^2.3.4",

src/app/app_router_config.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
function route(entry, resolve) {
2-
return {
3-
template: '<' + entry + '></' + entry + '>',
4-
resolve: {
5-
async: ['$q', function ($q) {
6-
const defer = $q.defer();
7-
8-
resolve(defer.resolve);
9-
return defer.promise;
10-
}]
11-
}
12-
};
13-
}
1+
const route = (entry, resolve) => ({
2+
template: '<' + entry + '></' + entry + '>',
3+
resolve: {
4+
async: ['$q', function ($q) {
5+
const defer = $q.defer();
6+
7+
resolve(defer.resolve);
8+
return defer.promise;
9+
}]
10+
}
11+
});
1412

1513

16-
const routerConfig = app => {
14+
export default app => {
1715
const $inject = ['$routeProvider'];
16+
17+
// We have to use hardcoded value for 'require' so it can be statically built
1818
const RouterConfig = function ($routeProvider) {
1919
$routeProvider
20+
2021
.when('/', {template: ''})
21-
.when('/home', route('home', callback => {
22-
require.ensure([], function () {
23-
// We have to use hardcoded value for 'require' so it can be statically built
24-
callback(app.register(require('./home').name));
25-
});
26-
}))
27-
.when('/about', route('about', callback => {
28-
require.ensure([], function () {
29-
callback(app.register(require('./about').name));
30-
});
31-
}))
32-
.when('/haml', route('haml', function (callback) {
33-
require.ensure([], function () {
34-
callback(app.register(require('./haml').name));
35-
});
36-
}))
22+
23+
.when('/home', route('home', callback =>
24+
require.ensure([], () =>
25+
callback(app.register(require('./home').name)))))
26+
27+
.when('/about', route('about', callback =>
28+
require.ensure([], () =>
29+
callback(app.register(require('./about').name)))))
30+
31+
.when('/haml', route('haml', callback =>
32+
require.ensure([], () =>
33+
callback(app.register(require('./haml').name)))))
34+
3735
.otherwise({redirectTo: '/'});
3836
};
3937

4038
RouterConfig.$inject = $inject;
4139

4240
return RouterConfig;
4341
};
44-
45-
export default routerConfig;

index.html renamed to src/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<html>
33
<head lang="en">
44
<meta charset="UTF-8">
5-
<title></title>
6-
<script src="./dest/app.js"></script>
5+
<title>Angular Webpack</title>
76
</head>
87
<body ng-app="app" ng-strict-di>
98

webpack.config.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var path = require('path');
2+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
3+
var HtmlWebpackPlugin = require('html-webpack-plugin');
24

35
module.exports = {
46
entry: {
@@ -11,14 +13,18 @@ module.exports = {
1113
output: {
1214
filename: '[name].js',
1315
path: './dest',
14-
publicPath: '.',
1516
chunkFilename: '[id].chunk.js'
1617
},
1718
module: {
1819
loaders: [
1920
{test: /\.js$/, loader: 'babel', include: path.resolve('src')},
20-
{test: /\.css$/, loader: 'style!css?sourceMap'},
21-
{test: /\.sass$/, loader: 'style!css?sourceMap!sass?sourceMap&indentedSyntax=true'},
21+
{test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css?sourceMap')},
22+
23+
{
24+
test: /\.sass$/,
25+
loader: ExtractTextPlugin
26+
.extract('style', 'css?sourceMap!sass?sourceMap&indentedSyntax=true')
27+
},
2228
{test: /\.(png|jpg)$/, loader: 'url?limit=32768'},
2329
{test: /\.html$/, loader: 'ng-cache?prefix=[dir]/[dir]'},
2430
{test: /\.haml$/, loader: 'hamlc-loader'}
@@ -27,15 +33,20 @@ module.exports = {
2733
/angular\.src\.js/
2834
]
2935
},
36+
plugins: [
37+
new ExtractTextPlugin('style.css', {allChunks: true}),
38+
new HtmlWebpackPlugin({
39+
template: path.resolve('src', 'index.html'),
40+
inject: 'body'
41+
})
42+
],
3043
devtool: 'eval',
3144
devServer: {
32-
hot: true,
3345
historyApiFallback: true,
3446
stats: {
3547
chunkModules: false,
3648
colors: true
3749
},
38-
contentBase: '.',
39-
publicPath: '.'
50+
contentBase: './src'
4051
}
4152
};

0 commit comments

Comments
 (0)
0