New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CommonsChunkPlugin example #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 00 TypeScript | ||
|
||
TBD |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "boilerplate", | ||
"version": "1.0.0", | ||
"description": "Front-End Lemoncode Master, Bundle Modules, Webpack Demo 00 Boilerplate", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "webpack-dev-server" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Lemoncode/webpack-2.x-by-sample.git" | ||
}, | ||
"author": "Lemoncode", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Lemoncode/webpack-2.x-by-sample/issues" | ||
}, | ||
"homepage": "https://github.com/Lemoncode/webpack-2.x-by-sample#readme", | ||
"devDependencies": { | ||
"@types/jquery": "^2.0.40", | ||
"@types/left-pad": "^1.1.0", | ||
"awesome-typescript-loader": "^3.1.2", | ||
"css-loader": "^0.26.2", | ||
"extract-text-webpack-plugin": "^2.0.0", | ||
"file-loader": "^0.10.1", | ||
"html-webpack-plugin": "^2.28.0", | ||
"left-pad": "^1.1.3", | ||
"node-sass": "^4.5.0", | ||
"sass-loader": "^6.0.2", | ||
"style-loader": "^0.13.2", | ||
"typescript": "^2.2.1", | ||
"url-loader": "^0.5.8", | ||
"webpack": "^2.2.1", | ||
"webpack-dev-server": "^2.4.1" | ||
}, | ||
"dependencies": { | ||
"bootstrap": "^3.3.7", | ||
"jquery": "^3.1.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function getAvg(scores): number { | ||
return getTotalScore(scores) / scores.length; | ||
} | ||
|
||
function getTotalScore(scores): number { | ||
return scores.reduce((score, count) => { | ||
return score + count; | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Webpack 2.x by sample</title> | ||
</head> | ||
<body> | ||
<div class="jumbotron"> | ||
<h1>Testing Bootstrap</h1> | ||
<p> | ||
Bootstrap is the most popular ... | ||
</p> | ||
</div> | ||
Hello Webpack 2! | ||
<div class="red-background "> | ||
RedBackground stuff | ||
</div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$blue-color: teal; | ||
|
||
.red-background { | ||
background-color: $blue-color; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {getAvg} from "./averageService"; | ||
import * as $ from 'jquery'; | ||
import leftPad = require('left-pad'); | ||
|
||
$('body').css('background-color', 'lightSkyBlue'); | ||
|
||
const scores: number[] = [90, 75, 60, 99, 94, 30]; | ||
const averageScore: number = getAvg(scores); | ||
|
||
const messageToDisplay: string = leftPad(`average score ${averageScore}`, 35, 'jorobateflanders'); | ||
|
||
document.write(messageToDisplay); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import 'jquery'; | ||
import 'left-pad'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"declaration": false, | ||
"noImplicitAny": false, | ||
"sourceMap": true, | ||
"noLib": false, | ||
"suppressImplicitAnyIndexErrors": true | ||
}, | ||
"compileOnSave": false, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
var path = require('path'); | ||
var HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
var webpack = require('webpack'); | ||
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
|
||
var basePath = __dirname; | ||
|
||
module.exports = { | ||
context: path.join(basePath, 'src'), | ||
resolve: { | ||
extensions: ['.js', '.ts'] | ||
}, | ||
entry: { | ||
app: './students.ts', | ||
appStyles: [ | ||
'./mystyles.scss', | ||
], | ||
vendor: './vendor.ts', | ||
vendorStyles: [ | ||
'../node_modules/bootstrap/dist/css/bootstrap.css', | ||
], | ||
}, | ||
output: { | ||
path: path.join(basePath, 'dist'), | ||
filename: '[chunkhash].[name].js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
loader: 'awesome-typescript-loader', | ||
}, | ||
{ | ||
test: /\.scss$/, | ||
exclude: /node_modules/, | ||
loader: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: [ | ||
{ loader: 'css-loader', }, | ||
{ loader: 'sass-loader', }, | ||
], | ||
}), | ||
}, | ||
{ | ||
test: /\.css$/, | ||
include: /node_modules/, | ||
loader: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: { | ||
loader: 'css-loader', | ||
}, | ||
}), | ||
}, | ||
// Loading glyphicons => https://github.com/gowravshekar/bootstrap-webpack | ||
// Using here url-loader and file-loader | ||
{ | ||
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, | ||
loader: 'url-loader?limit=10000&mimetype=application/font-woff' | ||
}, | ||
{ | ||
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, | ||
loader: 'url-loader?limit=10000&mimetype=application/octet-stream' | ||
}, | ||
{ | ||
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, | ||
loader: 'file-loader' | ||
}, | ||
{ | ||
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, | ||
loader: 'url-loader?limit=10000&mimetype=image/svg+xml' | ||
}, | ||
], | ||
}, | ||
// For development https://webpack.js.org/configuration/devtool/#for-development | ||
devtool: 'source-map', | ||
devServer: { | ||
port: 8080, | ||
}, | ||
plugins: [ | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: 'vendor' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have planned to explain something about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, my explanation is going to be very complete on everything related with CommonsChunkPlugin but this repo contains the final version of what I intend to explain. Between us, I don't see why you have an external manifest on that example, but I will explain the cons and pros of that and a good use case of when that is an awesome idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, thanks |
||
}), | ||
//Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin | ||
new HtmlWebpackPlugin({ | ||
filename: 'index.html', //Name of file in ./dist/ | ||
template: 'index.html', //Name of template in ./src | ||
hash: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the examples in here have that issue. It uses 3 tabs instead of 6 spaces and the copy & paste caught that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks. I have to open an issue for that |
||
}), | ||
new webpack.ProvidePlugin({ | ||
$: "jquery", | ||
jQuery: "jquery" | ||
}), | ||
new ExtractTextPlugin({ | ||
filename: '[chunkhash].[name].css', | ||
disable: false, | ||
allChunks: true, | ||
}), | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using
require
instead offrom
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the @types on it sucks big time. There is no way of using
from
with that. That is a typescript old type of import but there is no way of doing it in here because the types doesn't export a module.I used this library for being super simple on the output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also works a bit on explaining people that using
import ... from ...
is not working in all cases. In fact I have planned some talk about that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks