Skip to content

Commit a0b7181

Browse files
author
Marcello Montemagno
committed
First commit
0 parents  commit a0b7181

14 files changed

+181
-0
lines changed

.eslintrc.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
}
9+
},
10+
"rules":{
11+
"no-console":0
12+
}
13+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
builds/
3+
node_modules/

index.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<script src="builds/bundle.js"></script>
5+
</body>
6+
</html>

package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "seed",
3+
"version": "0.0.1",
4+
"description": "a simple seed",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "test",
8+
"build": "webpack --display-modules --display-chunks",
9+
"dist": "webpack --display-modules --display-chunks -production",
10+
"serve": "webpack-dev-server --inline --hot"
11+
},
12+
"author": "",
13+
"license": "ISC",
14+
"dependencies": {
15+
"jquery": "^2.2.1"
16+
},
17+
"devDependencies": {
18+
"babel-core": "^6.7.2",
19+
"babel-loader": "^6.2.4",
20+
"babel-preset-es2015": "^6.6.0",
21+
"clean-webpack-plugin": "^0.1.8",
22+
"css-loader": "^0.23.1",
23+
"eslint": "^2.4.0",
24+
"eslint-loader": "^1.3.0",
25+
"file-loader": "^0.8.5",
26+
"html-loader": "^0.4.3",
27+
"node-sass": "^3.4.2",
28+
"sass-loader": "^3.2.0",
29+
"style-loader": "^0.13.0",
30+
"url-loader": "^0.5.7",
31+
"webpack": "^1.12.14",
32+
"webpack-dev-server": "^1.14.1"
33+
}
34+
}

src/dogeWidget/DogeWidget.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import $ from 'jquery';
2+
import './style.scss';
3+
import template from './template.html';
4+
5+
export default class DogeWidget {
6+
7+
constructor() {}
8+
9+
render(node) {
10+
$(node).append(template);
11+
}
12+
13+
}

src/dogeWidget/doge.jpg

27.1 KB
Loading

src/dogeWidget/style.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.dogeWidget {
2+
background-image: url('./doge.jpg');
3+
background-size: cover;
4+
width: 100px;
5+
height: 100px;
6+
}

src/dogeWidget/template.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="dogeWidget"></div>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import $ from 'jquery';
2+
import './style.scss';
3+
import template from './template.html';
4+
5+
export default class GrumpyCatWidget {
6+
7+
constructor() {}
8+
9+
render(node) {
10+
$(node).append(template);
11+
}
12+
13+
}

src/grumpyCatWidget/grumpyCat.jpg

18.5 KB
Loading

src/grumpyCatWidget/style.scss

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.grumpyCatWidget {
2+
background-image: url('./grumpyCat.jpg');
3+
background-size: cover;
4+
width: 100px;
5+
height: 100px;
6+
}

src/grumpyCatWidget/template.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="grumpyCatWidget"></div>

src/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*global require*/
2+
3+
import $ from 'jquery';
4+
5+
require.ensure([], () => {
6+
var GrumpyCatWidget = require('./grumpyCatWidget/GrumpyCatWidget.js').default;
7+
new GrumpyCatWidget().render($('body'));
8+
},'grumpyChunk');
9+
10+
require.ensure([], () => {
11+
var DogeWidget = require('./dogeWidget/DogeWidget.js').default;
12+
new DogeWidget().render($('body'));
13+
},'dogeChunk');

webpack.config.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var webpack = require('webpack');
2+
var CleanPlugin = require('clean-webpack-plugin');
3+
4+
var isProductionMode = process.argv.indexOf('-production') != -1;
5+
6+
var buildDistPath = 'builds';
7+
8+
module.exports = {
9+
devtool: isProductionMode ? undefined : 'source-map',
10+
entry: './src',
11+
output: {
12+
path: buildDistPath,
13+
filename: 'bundle.js',
14+
chunkFilename: '[name].js', //allow to name split chunks
15+
publicPath: buildDistPath + '/'
16+
},
17+
module: {
18+
preLoaders: [
19+
{
20+
test: /\.js/,
21+
loader: 'eslint',
22+
}
23+
],
24+
loaders: [
25+
{
26+
test: /\.js/,
27+
exclude: /(node_modules|bower_components)/, //avoid that babel will treaverse files third-party code //TODO is it needed? webpack entry is ./src'
28+
loader: 'babel',
29+
query: {presets: ['es2015']}
30+
},
31+
{
32+
test: /\.html/,
33+
loader: 'html',
34+
},
35+
{
36+
test: /\.scss$/,
37+
loaders: ["style", "css", "sass"]
38+
},
39+
{
40+
test: /\.(png|gif|jpe?g|svg)$/i,
41+
loader: 'url',
42+
query: {limit: 10000} //if the asset is smaller than 10kb inline it, instead of giving the url
43+
}
44+
]
45+
},
46+
plugins:
47+
isProductionMode
48+
?
49+
[
50+
// Cleanup the builds/ folder before compiling
51+
new CleanPlugin(buildDistPath),
52+
// prevents creating chunks that would be too small to be worth loading separately
53+
new webpack.optimize.MinChunkSizePlugin({
54+
minChunkSize: 51200, // ~50kb
55+
}),
56+
//extract common chunks dependency into a shared js
57+
new webpack.optimize.CommonsChunkPlugin({
58+
name: 'main', // Move dependencies to our main file
59+
children: true, // Look for common dependencies in all children,
60+
minChunks: 2, // How many times a dependency must come up before being extracted
61+
}),
62+
//minify code
63+
new webpack.optimize.UglifyJsPlugin({
64+
mangle: true,
65+
compress: {
66+
warnings: false, // Suppress uglification warnings
67+
},
68+
})
69+
]
70+
:
71+
[]
72+
};

0 commit comments

Comments
 (0)