Skip to content

Commit 7d5bc83

Browse files
author
fabianmoronzirfas
committed
build(webpack and babel): added webpack and babel and husky for production build on push
re #79
1 parent 3df3421 commit 7d5bc83

File tree

8 files changed

+1433
-10
lines changed

8 files changed

+1433
-10
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

.eslintrc.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
'unobtrusive',
44
'eslint:recommended'
55
],
6-
plugins: [],
6+
plugins: ['babel'],
77
env: {
88
browser: true,
99
node: true,
@@ -25,4 +25,3 @@ module.exports = {
2525
'no-console': ['off','always']
2626
}
2727
};
28-

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ exclude:
4242
- test/
4343
- assets/js/src/
4444
- .cache
45+
- webpack.config

package-lock.json

Lines changed: 1364 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
"version": "0.1.0",
44
"description": "the docs for Basil.js",
55
"scripts": {
6+
"webpack:dev": "webpack --config webpack-config/index.js --env dev --colors --progress --watch",
7+
"webpack:prod": "webpack --config webpack-config/index.js --env prod --colors --progress",
8+
"jekyll:dev": "bundle exec jekyll serve --livereload --incremental --limit_posts 5",
9+
"jekyll:prod": "JEKYLL_ENV=production bundle exec jekyll build",
610
"build": "npm run update ; npm run generator",
711
"update": "npm run pull-latest-basil ; npm run generate-json",
812
"generator": "node .bin/index",
9-
"webpack": "webpack",
1013
"pull-latest-basil": "npm install basiljs/basil.js#develop -D",
1114
"generate-json": "documentation build ./node_modules/basiljs/basil.js -o ./.bin/api/data.json",
1215
"docs-json-test": "documentation build .bin/test/index.js -o .bin/test/api.json",
13-
"broken-link-check": "blc --filter-level 2 -r --input http://localhost:4000 > test/report.txt && cat test/report.txt | grep 'BROKEN'",
14-
"parcel:watch": "parcel watch -d assets/js/ reference.js"
16+
"broken-link-check": "blc --filter-level 2 -r --input http://localhost:4000 > test/report.txt && cat test/report.txt | grep 'BROKEN'"
1517
},
1618
"repository": {
1719
"type": "git",
@@ -29,14 +31,20 @@
2931
},
3032
"homepage": "https://github.com/basiljs/basiljs.github.io#readme",
3133
"devDependencies": {
34+
"@babel/core": "^7.2.2",
35+
"@babel/preset-env": "^7.2.3",
36+
"babel-loader": "^8.0.4",
3237
"basiljs": "github:basiljs/basil.js#develop",
3338
"cz-conventional-changelog": "^2.1.0",
3439
"documentation": "^6.1.0",
3540
"eslint": "^5.6.0",
3641
"eslint-config-unobtrusive": "^1.2.2",
42+
"eslint-plugin-babel": "^5.3.0",
3743
"fs-extra": "^2.0.0",
44+
"husky": "^1.2.1",
3845
"jquery": "^3.3.1",
3946
"lodash": "^4.17.10",
47+
"p5": "^0.7.2",
4048
"path-exists": "^3.0.0",
4149
"webpack": "^4.28.0",
4250
"webpack-cli": "^3.1.2",
@@ -52,5 +60,10 @@
5260
"commitizen": {
5361
"path": "./node_modules/cz-conventional-changelog"
5462
}
63+
},
64+
"husky": {
65+
"hooks": {
66+
"pre-push": "npm run webpack:prod && npm run jekyll:prod"
67+
}
5568
}
5669
}

webpack.config.js renamed to webpack-config/dev.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const webpack = require('webpack');
66

77
module.exports = {
88
watch: true,
9-
mode: 'production',
9+
mode: 'development',
1010
devtool: 'source-map',
1111
target:'web',
12-
context: path.resolve(__dirname, './'),
12+
context: path.resolve(__dirname, '../'),
1313
entry: {
1414
reference: './assets/js/src/reference.js',
1515
main:'./assets/js/src/main.js'
@@ -18,9 +18,16 @@ module.exports = {
1818
jquery: 'jQuery'
1919
},
2020
output: {
21-
path: path.resolve(__dirname, './assets/js'),
21+
path: path.resolve(__dirname, '../', './assets/js'),
2222
filename: '[name].bundle.js'
2323
},
24+
module: {
25+
rules: [
26+
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', options: {
27+
presets: ['@babel/preset-env']
28+
}}
29+
]
30+
},
2431
// if we want to refernce our css within the js this is the way to go
2532
// but it seems a bit odd to require('style.css') in a css file.
2633
// Still - this would add the css to the head of the index.html file

webpack-config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = env => require(`./${env}.js`);

webpack-config/prod.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path');
2+
// eslint-disable-next-line no-unused-vars
3+
const webpack = require('webpack');
4+
// if we want to create a sseparate css file we
5+
// need this module
6+
7+
module.exports = {
8+
watch: false,
9+
mode: 'production',
10+
devtool: 'source-map',
11+
target:'web',
12+
context: path.resolve(__dirname, '../'),
13+
entry: {
14+
reference: './assets/js/src/reference.js',
15+
main:'./assets/js/src/main.js'
16+
},
17+
externals: {
18+
},
19+
output: {
20+
path: path.resolve(__dirname, '../', './assets/js'),
21+
filename: '[name].bundle.js'
22+
},
23+
module: {
24+
rules: [
25+
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', options: {
26+
presets: ['@babel/preset-env']
27+
}}
28+
]
29+
},
30+
optimization: {
31+
splitChunks: {
32+
chunks: 'all'
33+
}
34+
},
35+
plugins: [
36+
]
37+
};

0 commit comments

Comments
 (0)