Skip to content

Commit c71e1d0

Browse files
committed
feat(webpack): added webpack version
1 parent a7b30d6 commit c71e1d0

113 files changed

Lines changed: 3617 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ npm-debug.log
6363
.idea/
6464
*.swp
6565

66-
/src/**.*.js
67-
/src/**.*.js.map
66+
src/**.*.js
67+
src/**.*.js.map
6868

6969
# Angular #
7070
*.ngfactory.ts

config/db.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"heroesPowers": [
3+
"Really Smart",
4+
"Super Flexible",
5+
"Super Hot",
6+
"Weather Changer"
7+
],
8+
"heroes": [
9+
{
10+
"id": 11,
11+
"name": "Mr. Nice",
12+
"power": "Really Smart",
13+
"alterEgo": "nice"
14+
},
15+
{
16+
"id": 12,
17+
"name": "Narco",
18+
"power": "Weather Changer",
19+
"alterEgo": "pe"
20+
},
21+
{
22+
"id": 13,
23+
"name": "Bombasto",
24+
"power": "Weather Changer",
25+
"alterEgo": "bombi"
26+
},
27+
{
28+
"id": 14,
29+
"name": "Celeritas",
30+
"power": "Super Hot",
31+
"alterEgo": "cele"
32+
},
33+
{
34+
"id": 15,
35+
"name": "Magneta",
36+
"power": "Really Smart",
37+
"alterEgo": "magne"
38+
},
39+
{
40+
"id": 16,
41+
"name": "RubberMan",
42+
"power": "Super Flexible",
43+
"alterEgo": "rubb"
44+
},
45+
{
46+
"id": 17,
47+
"name": "Dynama",
48+
"power": "Super Flexible",
49+
"alterEgo": "dy"
50+
},
51+
{
52+
"id": 18,
53+
"name": "Dr IQ",
54+
"power": "Really Smart",
55+
"alterEgo": "iq"
56+
},
57+
{
58+
"id": 19,
59+
"name": "Magma",
60+
"power": "Super Flexible",
61+
"alterEgo": "cold"
62+
},
63+
{
64+
"id": 20,
65+
"name": "Tornado",
66+
"power": "Really Smart",
67+
"alterEgo": "torny"
68+
}
69+
]
70+
}

config/empty.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
NgProbeToken: {},
3+
HmrState: function() {},
4+
_createConditionalRootRenderer: function(rootRenderer, extraTokens, coreTokens) {
5+
return rootRenderer;
6+
},
7+
__platform_browser_private__: {}
8+
};

config/head-config.common.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = {
2+
link: [
3+
/** <link> tags for 'apple-touch-icon' (AKA Web Clips). **/
4+
{ rel: 'apple-touch-icon', sizes: '57x57', href: '/assets/icon/apple-icon-57x57.png' },
5+
{ rel: 'apple-touch-icon', sizes: '60x60', href: '/assets/icon/apple-icon-60x60.png' },
6+
{ rel: 'apple-touch-icon', sizes: '72x72', href: '/assets/icon/apple-icon-72x72.png' },
7+
{ rel: 'apple-touch-icon', sizes: '76x76', href: '/assets/icon/apple-icon-76x76.png' },
8+
{ rel: 'apple-touch-icon', sizes: '114x114', href: '/assets/icon/apple-icon-114x114.png' },
9+
{ rel: 'apple-touch-icon', sizes: '120x120', href: '/assets/icon/apple-icon-120x120.png' },
10+
{ rel: 'apple-touch-icon', sizes: '144x144', href: '/assets/icon/apple-icon-144x144.png' },
11+
{ rel: 'apple-touch-icon', sizes: '152x152', href: '/assets/icon/apple-icon-152x152.png' },
12+
{ rel: 'apple-touch-icon', sizes: '180x180', href: '/assets/icon/apple-icon-180x180.png' },
13+
14+
/** <link> tags for android web app icons **/
15+
{ rel: 'icon', type: 'image/png', sizes: '192x192', href: '/assets/icon/android-icon-192x192.png' },
16+
17+
/** <link> tags for favicons **/
18+
{ rel: 'icon', type: 'image/png', sizes: '32x32', href: '/assets/icon/favicon-32x32.png' },
19+
{ rel: 'icon', type: 'image/png', sizes: '96x96', href: '/assets/icon/favicon-96x96.png' },
20+
{ rel: 'icon', type: 'image/png', sizes: '16x16', href: '/assets/icon/favicon-16x16.png' },
21+
22+
/** <link> tags for a Web App Manifest **/
23+
{ rel: 'manifest', href: '/assets/manifest.json' },
24+
25+
{ rel: 'stylesheet', href: '/assets/css/styles.css' }
26+
],
27+
meta: [
28+
{ name: 'msapplication-TileColor', content: '#00bcd4' },
29+
{ name: 'msapplication-TileImage', content: '/assets/icon/ms-icon-144x144.png', '=content': true },
30+
{ name: 'theme-color', content: '#00bcd4' }
31+
]
32+
};

config/helpers.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var path = require('path');
2+
3+
const EVENT = process.env.npm_lifecycle_event || '';
4+
5+
// Helper functions
6+
var ROOT = path.resolve(__dirname, '..');
7+
8+
function hasProcessFlag(flag) {
9+
return process.argv.join('').indexOf(flag) > -1;
10+
}
11+
12+
function hasNpmFlag(flag) {
13+
return EVENT.includes(flag);
14+
}
15+
16+
function isWebpackDevServer() {
17+
return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1]));
18+
}
19+
20+
function root(args) {
21+
args = Array.prototype.slice.call(arguments, 0);
22+
return path.join.apply(path, [ROOT].concat(args));
23+
}
24+
25+
exports.hasProcessFlag = hasProcessFlag;
26+
exports.hasNpmFlag = hasNpmFlag;
27+
exports.isWebpackDevServer = isWebpackDevServer;
28+
exports.root = root;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
function HtmlElementsPlugin(locations) {
3+
this.locations = locations;
4+
}
5+
6+
HtmlElementsPlugin.prototype.apply = function(compiler) {
7+
var self = this;
8+
compiler.plugin('compilation', function(compilation) {
9+
compilation.options.htmlElements = compilation.options.htmlElements || {};
10+
11+
compilation.plugin('html-webpack-plugin-before-html-generation', function(htmlPluginData, callback) {
12+
const locations = self.locations;
13+
14+
if (locations) {
15+
const publicPath = htmlPluginData.assets.publicPath;
16+
17+
Object.getOwnPropertyNames(locations).forEach(function(loc) {
18+
compilation.options.htmlElements[loc] = getHtmlElementString(locations[loc], publicPath);
19+
});
20+
}
21+
22+
23+
callback(null, htmlPluginData);
24+
});
25+
});
26+
27+
};
28+
29+
const RE_ENDS_WITH_BS = /\/$/;
30+
31+
/**
32+
* Create an HTML tag with attributes from a map.
33+
*
34+
* Example:
35+
* createTag('link', { rel: "manifest", href: "/assets/manifest.json" })
36+
* // <link rel="manifest" href="/assets/manifest.json">
37+
* @param tagName The name of the tag
38+
* @param attrMap A Map of attribute names (keys) and their values.
39+
* @param publicPath a path to add to eh start of static asset url
40+
* @returns {string}
41+
*/
42+
function createTag(tagName, attrMap, publicPath) {
43+
publicPath = publicPath || '';
44+
45+
// add trailing slash if we have a publicPath and it doesn't have one.
46+
if (publicPath && !RE_ENDS_WITH_BS.test(publicPath)) {
47+
publicPath += '/';
48+
}
49+
50+
const attributes = Object.getOwnPropertyNames(attrMap)
51+
.filter(function(name) { return name[0] !== '='; } )
52+
.map(function(name) {
53+
var value = attrMap[name];
54+
55+
if (publicPath) {
56+
// check if we have explicit instruction, use it if so (e.g: =herf: false)
57+
// if no instruction, use public path if it's href attribute.
58+
const usePublicPath = attrMap.hasOwnProperty('=' + name) ? !!attrMap['=' + name] : name === 'href';
59+
60+
if (usePublicPath) {
61+
// remove a starting trailing slash if the value has one so we wont have //
62+
value = publicPath + (value[0] === '/' ? value.substr(1) : value);
63+
}
64+
}
65+
66+
return `${name}="${value}"`;
67+
});
68+
69+
const closingTag = tagName === 'script' ? '</script>' : '';
70+
71+
return `<${tagName} ${attributes.join(' ')}>${closingTag}`;
72+
}
73+
74+
/**
75+
* Returns a string representing all html elements defined in a data source.
76+
*
77+
* Example:
78+
*
79+
* const ds = {
80+
* link: [
81+
* { rel: "apple-touch-icon", sizes: "57x57", href: "/assets/icon/apple-icon-57x57.png" }
82+
* ],
83+
* meta: [
84+
* { name: "msapplication-TileColor", content: "#00bcd4" }
85+
* ]
86+
* }
87+
*
88+
* getHeadTags(ds);
89+
* // "<link rel="apple-touch-icon" sizes="57x57" href="/assets/icon/apple-icon-57x57.png">"
90+
* "<meta name="msapplication-TileColor" content="#00bcd4">"
91+
*
92+
* @returns {string}
93+
*/
94+
function getHtmlElementString(dataSource, publicPath) {
95+
return Object.getOwnPropertyNames(dataSource)
96+
.map(function(name) {
97+
if (Array.isArray(dataSource[name])) {
98+
return dataSource[name].map(function(attrs) { return createTag(name, attrs, publicPath); } );
99+
} else {
100+
return [ createTag(name, dataSource[name], publicPath) ];
101+
}
102+
})
103+
.reduce(function(arr, curr) {
104+
return arr.concat(curr);
105+
}, [])
106+
.join('\n\t');
107+
}
108+
module.exports = HtmlElementsPlugin;

config/karma.conf.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
module.exports = function (config) {
2+
var testWebpackConfig = require('./webpack.test.js')({ env: 'test' });
3+
4+
var configuration = {
5+
6+
// base path that will be used to resolve all patterns (e.g. files, exclude)
7+
basePath: '',
8+
9+
/*
10+
* Frameworks to use
11+
*
12+
* available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
*/
14+
frameworks: ['jasmine'],
15+
16+
// list of files to exclude
17+
exclude: [],
18+
19+
client: {
20+
captureConsole: false
21+
},
22+
23+
/*
24+
* list of files / patterns to load in the browser
25+
*
26+
* we are building the test environment in ./spec-bundle.js
27+
*/
28+
files: [
29+
{ pattern: './config/spec-bundle.js', watched: false },
30+
{ pattern: './src/assets/**/*', watched: false, included: false, served: true, nocache: false }
31+
],
32+
33+
/*
34+
* By default all assets are served at http://localhost:[PORT]/base/
35+
*/
36+
proxies: {
37+
"/assets/": "/base/src/assets/"
38+
},
39+
40+
/*
41+
* preprocess matching files before serving them to the browser
42+
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
43+
*/
44+
preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
45+
46+
// Webpack Config at ./webpack.test.js
47+
webpack: testWebpackConfig,
48+
49+
coverageReporter: {
50+
type: 'in-memory'
51+
},
52+
53+
remapCoverageReporter: {
54+
'text-summary': null,
55+
json: './coverage/coverage.json',
56+
html: './coverage/html'
57+
},
58+
59+
// Webpack please don't spam the console when running in karma!
60+
webpackMiddleware: {
61+
// webpack-dev-middleware configuration
62+
// i.e.
63+
noInfo: true,
64+
// and use stats to turn off verbose output
65+
stats: {
66+
// options i.e.
67+
chunks: false
68+
}
69+
},
70+
71+
/*
72+
* test results reporter to use
73+
*
74+
* possible values: 'dots', 'progress'
75+
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
76+
*/
77+
reporters: ['mocha', 'coverage', 'remap-coverage'],
78+
79+
// web server port
80+
port: 9876,
81+
82+
// enable / disable colors in the output (reporters and logs)
83+
colors: true,
84+
85+
/*
86+
* level of logging
87+
* possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
88+
*/
89+
logLevel: config.LOG_WARN,
90+
91+
// enable / disable watching file and executing tests whenever any file changes
92+
autoWatch: false,
93+
94+
/*
95+
* start these browsers
96+
* available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
97+
*/
98+
browsers: [
99+
'Chrome'
100+
],
101+
102+
customLaunchers: {
103+
ChromeTravisCi: {
104+
base: 'Chrome',
105+
flags: ['--no-sandbox']
106+
}
107+
},
108+
109+
/*
110+
* Continuous Integration mode
111+
* if true, Karma captures browsers, runs the tests and exits
112+
*/
113+
singleRun: true
114+
};
115+
116+
if (process.env.TRAVIS) {
117+
configuration.browsers = [
118+
'ChromeTravisCi'
119+
];
120+
}
121+
122+
config.set(configuration);
123+
};

0 commit comments

Comments
 (0)