Skip to content

Commit 614e450

Browse files
committed
Got a nice working es6 webpack project
Used the Yeoman fountain webapp generator, made a react project, ripped out all react stuff, and made the followiing webpack fix: webpack-contrib/uglifyjs-webpack-plugin#33 requires "uglifyjs-webpack-plugin": "0.4.3",
1 parent 3a95052 commit 614e450

25 files changed

+672
-0
lines changed

configurator/.babelrc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
],
5+
"env": {
6+
"test": {
7+
"plugins": [
8+
"istanbul"
9+
]
10+
},
11+
"production": {
12+
"presets": [
13+
[
14+
"es2015",
15+
{
16+
"modules": false
17+
}
18+
]
19+
]
20+
}
21+
}
22+
}

configurator/.editorconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true

configurator/.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

configurator/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.tmp/
2+
coverage/
3+
dist/
4+
node_modules/

configurator/.yo-rc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"generator-fountain-react": {
3+
"version": "1.0.0",
4+
"props": {
5+
"framework": "react",
6+
"modules": "webpack",
7+
"js": "babel",
8+
"ci": "",
9+
"css": "css",
10+
"resolved": "/Users/torchh/.nvm/versions/node/v6.10.3/lib/node_modules/generator-fountain-webapp/node_modules/generator-fountain-react/generators/app/index.js",
11+
"namespace": "fountain-react:app",
12+
"_": [],
13+
"sample": "hello",
14+
"router": "none"
15+
}
16+
}
17+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const conf = require('./gulp.conf');
2+
3+
module.exports = function () {
4+
return {
5+
server: {
6+
baseDir: [
7+
conf.paths.dist
8+
]
9+
},
10+
open: false
11+
};
12+
};

configurator/conf/browsersync.conf.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const conf = require('./gulp.conf');
2+
3+
const webpack = require('webpack');
4+
const webpackDevMiddleware = require('webpack-dev-middleware');
5+
const webpackHotMiddleware = require('webpack-hot-middleware');
6+
7+
const webpackConf = require('./webpack.conf');
8+
const webpackBundler = webpack(webpackConf);
9+
10+
module.exports = function () {
11+
return {
12+
server: {
13+
baseDir: [
14+
conf.paths.tmp,
15+
conf.paths.src
16+
],
17+
middleware: [
18+
webpackDevMiddleware(webpackBundler, {
19+
// IMPORTANT: dev middleware can't access config, so we should
20+
// provide publicPath by ourselves
21+
publicPath: webpackConf.output.publicPath,
22+
23+
// Quiet verbose output in console
24+
quiet: true
25+
}),
26+
27+
// bundler should be the same as above
28+
webpackHotMiddleware(webpackBundler)
29+
]
30+
},
31+
open: false
32+
};
33+
};

configurator/conf/gulp.conf.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
/**
4+
* This file contains the variables used in other gulp files
5+
* which defines tasks
6+
* By design, we only put there very generic config values
7+
* which are used in several places to keep good readability
8+
* of the tasks
9+
*/
10+
11+
const path = require('path');
12+
const gutil = require('gulp-util');
13+
14+
/**
15+
* The main paths of your project handle these with care
16+
*/
17+
exports.paths = {
18+
src: 'src',
19+
dist: 'dist',
20+
tmp: '.tmp',
21+
e2e: 'e2e',
22+
tasks: 'gulp_tasks'
23+
};
24+
25+
/**
26+
* used on gulp dist
27+
*/
28+
exports.htmlmin = {
29+
ignoreCustomFragments: [/{{.*?}}/]
30+
};
31+
32+
exports.path = {};
33+
for (const pathName in exports.paths) {
34+
if (Object.prototype.hasOwnProperty.call(exports.paths, pathName)) {
35+
exports.path[pathName] = function () {
36+
const pathValue = exports.paths[pathName];
37+
const funcArgs = Array.prototype.slice.call(arguments);
38+
const joinArgs = [pathValue].concat(funcArgs);
39+
return path.join.apply(this, joinArgs);
40+
};
41+
}
42+
}
43+
44+
/**
45+
* Common implementation for an error handler of a Gulp plugin
46+
*/
47+
exports.errorHandler = function (title) {
48+
return function (err) {
49+
gutil.log(gutil.colors.red(`[${title}]`), err.toString());
50+
this.emit('end');
51+
};
52+
};

configurator/conf/karma-auto.conf.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const conf = require('./gulp.conf');
2+
3+
module.exports = function (config) {
4+
const configuration = {
5+
basePath: '../',
6+
singleRun: false,
7+
autoWatch: true,
8+
logLevel: 'INFO',
9+
junitReporter: {
10+
outputDir: 'test-reports'
11+
},
12+
browsers: [
13+
'PhantomJS'
14+
],
15+
frameworks: [
16+
'jasmine'
17+
],
18+
files: [
19+
'node_modules/es6-shim/es6-shim.js',
20+
conf.path.src('index.spec.js')
21+
],
22+
preprocessors: {
23+
[conf.path.src('index.spec.js')]: [
24+
'webpack'
25+
]
26+
},
27+
reporters: ['progress', 'coverage'],
28+
coverageReporter: {
29+
type: 'html',
30+
dir: 'coverage/'
31+
},
32+
webpack: require('./webpack-test.conf'),
33+
webpackMiddleware: {
34+
noInfo: true
35+
},
36+
plugins: [
37+
require('karma-jasmine'),
38+
require('karma-junit-reporter'),
39+
require('karma-coverage'),
40+
require('karma-phantomjs-launcher'),
41+
require('karma-phantomjs-shim'),
42+
require('karma-webpack')
43+
]
44+
};
45+
46+
config.set(configuration);
47+
};

configurator/conf/karma.conf.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const conf = require('./gulp.conf');
2+
3+
module.exports = function (config) {
4+
const configuration = {
5+
basePath: '../',
6+
singleRun: true,
7+
autoWatch: false,
8+
logLevel: 'INFO',
9+
junitReporter: {
10+
outputDir: 'test-reports'
11+
},
12+
browsers: [
13+
'PhantomJS'
14+
],
15+
frameworks: [
16+
'jasmine'
17+
],
18+
files: [
19+
'node_modules/es6-shim/es6-shim.js',
20+
conf.path.src('index.spec.js')
21+
],
22+
preprocessors: {
23+
[conf.path.src('index.spec.js')]: [
24+
'webpack'
25+
]
26+
},
27+
reporters: ['progress', 'coverage'],
28+
coverageReporter: {
29+
type: 'html',
30+
dir: 'coverage/'
31+
},
32+
webpack: require('./webpack-test.conf'),
33+
webpackMiddleware: {
34+
noInfo: true
35+
},
36+
plugins: [
37+
require('karma-jasmine'),
38+
require('karma-junit-reporter'),
39+
require('karma-coverage'),
40+
require('karma-phantomjs-launcher'),
41+
require('karma-phantomjs-shim'),
42+
require('karma-webpack')
43+
]
44+
};
45+
46+
config.set(configuration);
47+
};
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const webpack = require('webpack');
2+
const conf = require('./gulp.conf');
3+
const path = require('path');
4+
5+
const HtmlWebpackPlugin = require('html-webpack-plugin');
6+
// Doing a webpack hack for es6: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/33
7+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
8+
const FailPlugin = require('webpack-fail-plugin');
9+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
10+
const pkg = require('../package.json');
11+
const autoprefixer = require('autoprefixer');
12+
13+
module.exports = {
14+
module: {
15+
loaders: [
16+
{
17+
test: /\.json$/,
18+
loaders: [
19+
'json-loader'
20+
]
21+
},
22+
{
23+
test: /\.js$/,
24+
exclude: /node_modules/,
25+
loader: 'eslint-loader',
26+
enforce: 'pre'
27+
},
28+
{
29+
test: /\.css$/,
30+
loaders: ExtractTextPlugin.extract({
31+
fallback: 'style-loader',
32+
use: 'css-loader?minimize!postcss-loader'
33+
})
34+
},
35+
{
36+
test: /\.js$/,
37+
exclude: /node_modules/,
38+
loaders: [
39+
'babel-loader'
40+
]
41+
}
42+
]
43+
},
44+
plugins: [
45+
new webpack.optimize.OccurrenceOrderPlugin(),
46+
new webpack.NoEmitOnErrorsPlugin(),
47+
FailPlugin,
48+
new HtmlWebpackPlugin({
49+
template: conf.path.src('index.html')
50+
}),
51+
new webpack.DefinePlugin({
52+
'process.env.NODE_ENV': '"production"'
53+
}),
54+
new UglifyJsPlugin({
55+
output: {comments: false},
56+
compress: {unused: true, dead_code: true, warnings: false} // eslint-disable-line camelcase
57+
}),
58+
new ExtractTextPlugin('index-[contenthash].css'),
59+
new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}),
60+
new webpack.LoaderOptionsPlugin({
61+
options: {
62+
postcss: () => [autoprefixer]
63+
}
64+
})
65+
],
66+
output: {
67+
path: path.join(process.cwd(), conf.paths.dist),
68+
filename: '[name]-[hash].js'
69+
},
70+
entry: {
71+
app: `./${conf.path.src('index')}`,
72+
vendor: Object.keys(pkg.dependencies)
73+
}
74+
};
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const webpack = require('webpack');
2+
module.exports = {
3+
module: {
4+
loaders: [
5+
{
6+
test: /\.json$/,
7+
loaders: [
8+
'json-loader'
9+
]
10+
},
11+
{
12+
test: /\.js$/,
13+
exclude: /node_modules/,
14+
loader: 'eslint-loader',
15+
enforce: 'pre'
16+
},
17+
{
18+
test: /\.js$/,
19+
exclude: /node_modules/,
20+
loaders: [
21+
'babel-loader'
22+
]
23+
}
24+
]
25+
},
26+
plugins: [
27+
new webpack.LoaderOptionsPlugin({
28+
options: {},
29+
debug: true
30+
})
31+
],
32+
devtool: 'source-map',
33+
externals: {}
34+
};

0 commit comments

Comments
 (0)