Skip to content

Commit 3a3c5c3

Browse files
committed
first commit
0 parents  commit 3a3c5c3

24 files changed

+398
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Angular and Webpack Skeleton
2+
3+
## Install
4+
5+
Clone this repository, remove .git dir and run `npm install`
6+
7+
## Usage
8+
9+
Create your app in src diretory.
10+
11+
Commands:
12+
13+
- `npm start` - run developer server in port 8080
14+
- `npm run build` - run de build tasks to production (in **dist** directory)
15+
- `npm test` - run de tests
16+
17+
## Contributing
18+
19+
Only send PRs to this repository.

config/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var path = require('path');
2+
var _root = path.resolve(__dirname, '..');
3+
function root(args) {
4+
args = Array.prototype.slice.call(arguments, 0);
5+
return path.join.apply(path, [_root].concat(args));
6+
}
7+
exports.root = root;

config/karma-test-shim.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Error.stackTraceLimit = Infinity;
2+
3+
require('core-js/es6');
4+
require('core-js/es7/reflect');
5+
6+
require('zone.js/dist/zone');
7+
require('zone.js/dist/long-stack-trace-zone');
8+
require('zone.js/dist/proxy');
9+
require('zone.js/dist/sync-test');
10+
require('zone.js/dist/jasmine-patch');
11+
require('zone.js/dist/async-test');
12+
require('zone.js/dist/fake-async-test');
13+
14+
var appContext = require.context('../src', true, /\.spec\.ts/);
15+
16+
appContext.keys().forEach(appContext);
17+
18+
var testing = require('@angular/core/testing');
19+
var browser = require('@angular/platform-browser-dynamic/testing');
20+
21+
testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());

config/karma.conf.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var webpackConfig = require('./webpack.test');
2+
3+
module.exports = function (config) {
4+
var _config = {
5+
basePath: '',
6+
7+
frameworks: ['jasmine'],
8+
9+
files: [
10+
{pattern: './config/karma-test-shim.js', watched: false}
11+
],
12+
13+
preprocessors: {
14+
'./config/karma-test-shim.js': ['webpack', 'sourcemap']
15+
},
16+
17+
webpack: webpackConfig,
18+
19+
webpackMiddleware: {
20+
stats: 'errors-only'
21+
},
22+
23+
webpackServer: {
24+
noInfo: true
25+
},
26+
27+
reporters: ['progress'],
28+
port: 9876,
29+
colors: true,
30+
logLevel: config.LOG_INFO,
31+
autoWatch: false,
32+
browsers: ['PhantomJS'],
33+
singleRun: true
34+
};
35+
36+
config.set(_config);
37+
};

config/webpack.common.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
var webpack = require('webpack');
2+
var HtmlWebpackPlugin = require('html-webpack-plugin');
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
var helpers = require('./helpers');
5+
6+
module.exports = {
7+
entry: {
8+
'polyfills': './src/polyfills.ts',
9+
'vendor': './src/vendor.ts',
10+
'app': './src/main.ts'
11+
},
12+
13+
resolve: {
14+
extensions: ['', '.ts', '.js']
15+
},
16+
17+
module: {
18+
loaders: [
19+
{
20+
test: /\.ts$/,
21+
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
22+
},
23+
{
24+
test: /\.html$/,
25+
loader: 'html'
26+
},
27+
{
28+
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
29+
loader: 'file?name=assets/[name].[hash].[ext]'
30+
},
31+
{
32+
test: /\.css$/,
33+
exclude: helpers.root('src', 'app'),
34+
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
35+
},
36+
{
37+
test: /\.css$/,
38+
include: helpers.root('src', 'app'),
39+
loader: 'raw'
40+
}
41+
]
42+
},
43+
44+
plugins: [
45+
new webpack.optimize.CommonsChunkPlugin({
46+
name: ['app', 'vendor', 'polyfills']
47+
}),
48+
49+
new HtmlWebpackPlugin({
50+
template: 'src/index.html'
51+
})
52+
]
53+
};

config/webpack.dev.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var webpackMerge = require('webpack-merge');
2+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
3+
var commonConfig = require('./webpack.common.js');
4+
var helpers = require('./helpers');
5+
6+
module.exports = webpackMerge(commonConfig, {
7+
devtool: 'cheap-module-eval-source-map',
8+
9+
output: {
10+
path: helpers.root('dist'),
11+
publicPath: 'http://localhost:8080/',
12+
filename: '[name].js',
13+
chunkFilename: '[id].chunk.js'
14+
},
15+
16+
plugins: [
17+
new ExtractTextPlugin('[name].css')
18+
],
19+
20+
devServer: {
21+
historyApiFallback: true,
22+
stats: 'minimal'
23+
}
24+
});

config/webpack.prod.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var webpack = require('webpack');
2+
var webpackMerge = require('webpack-merge');
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
var commonConfig = require('./webpack.common.js');
5+
var helpers = require('./helpers');
6+
7+
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
8+
9+
module.exports = webpackMerge(commonConfig, {
10+
devtool: 'source-map',
11+
12+
output: {
13+
path: helpers.root('dist'),
14+
publicPath: '/',
15+
filename: '[name].[hash].js',
16+
chunkFilename: '[id].[hash].chunk.js'
17+
},
18+
19+
htmlLoader: {
20+
minimize: false // workaround for ng2
21+
},
22+
23+
plugins: [
24+
new webpack.NoErrorsPlugin(),
25+
new webpack.optimize.DedupePlugin(),
26+
new webpack.optimize.UglifyJsPlugin({ // https://github.com/angular/angular/issues/10618
27+
mangle: {
28+
keep_fnames: true
29+
}
30+
}),
31+
new ExtractTextPlugin('[name].[hash].css'),
32+
new webpack.DefinePlugin({
33+
'process.env': {
34+
'ENV': JSON.stringify(ENV)
35+
}
36+
})
37+
]
38+
});

config/webpack.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var helpers = require('./helpers');
2+
3+
module.exports = {
4+
devtool: 'inline-source-map',
5+
6+
resolve: {
7+
extensions: ['', '.ts', '.js']
8+
},
9+
10+
module: {
11+
loaders: [
12+
{
13+
test: /\.ts$/,
14+
loaders: ['awesome-typescript-loader', 'angular2-template-loader']
15+
},
16+
{
17+
test: /\.html$/,
18+
loader: 'html'
19+
20+
},
21+
{
22+
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
23+
loader: 'null'
24+
},
25+
{
26+
test: /\.css$/,
27+
exclude: helpers.root('src', 'app'),
28+
loader: 'null'
29+
},
30+
{
31+
test: /\.css$/,
32+
include: helpers.root('src', 'app'),
33+
loader: 'raw'
34+
}
35+
]
36+
}
37+
}

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./config/karma.conf.js');

0 commit comments

Comments
 (0)