Skip to content

Commit 0e749d4

Browse files
committedJan 18, 2017
Updated to webpack 2, moved some scritps to bin folder, not working yet
1 parent 678b295 commit 0e749d4

16 files changed

+6177
-102
lines changed
 

‎.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[*]
22
indent_style = space
3-
end_of_line = crlf
3+
end_of_line = lf
44
indent_size = 2
55
charset = utf-8
66
trim_trailing_whitespace = true

‎.eslintrc

+17-32
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,29 @@
11
{
2+
"root": true,
23
"parser": "babel-eslint",
3-
"extends": "eslint-config-airbnb",
44
"env": {
5-
"browser": false,
65
"node": true,
7-
"jasmine": false,
8-
"es6": true
6+
"es6": true,
7+
"browser": false
98
},
9+
"extends": "airbnb",
1010
"ecmaFeatures": {
1111
"modules": false
1212
},
1313
"rules": {
14-
"strict": 0,
15-
no-undef: 2,
16-
"max-len": [2, 200, 4],
17-
"react/jsx-uses-react": 2,
18-
"react/jsx-uses-vars": 2,
19-
"react/react-in-jsx-scope": 2,
20-
"indent": [2, 2, {"SwitchCase": 1}],
21-
"react/jsx-boolean-value": 0,
22-
// Temporarirly disabled due to a possible bug in babel-eslint (todomvc example)
23-
//"block-scoped-var": 0,
24-
// Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
25-
"padded-blocks": 0,
26-
"comma-dangle": [2, "never"], // not sure why airbnb turned this on. gross!
27-
"react/prefer-stateless-function": 0, // not sure why airbnb turned this on. gross!
28-
"id-length": 0, // not sure why airbnb turned this on. gross!
29-
"no-underscore-dangle": 0,
14+
"react/prefer-stateless-function": [0],
15+
"import/extensions": [0],
16+
"import/no-extraneous-dependencies": [2, {"devDependencies": true, "optionalDependencies": true}],
17+
"arrow-parens": [2, "as-needed"],
18+
"no-underscore-dangle": [2, { "allowAfterThis": true }],
3019
"no-console": 0,
31-
"no-alert": 0
32-
},
33-
"plugins": [
34-
"react"
35-
],
36-
"globals": {
37-
"__DEV__": false,
38-
"__PROD__": false,
39-
"__CORDOVA__": false,
40-
"__DEVTOOLS__": false,
41-
"__CLIENT__": false,
42-
"__SERVER__": false
20+
"comma-dangle": [2, "never"], // not sure why airbnb turned this on. gross!
21+
"max-len": [2, 200, 4],
22+
"no-else-return": 0,
23+
"new-cap": 0,
24+
"prefer-template": 0,
25+
"arrow-body-style": 0,
26+
"no-nested-ternary": 0,
27+
"default-case": 0
4328
}
4429
}

‎bin/build.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const webpack = require('webpack');
2+
const getWebpackConfig = require('./get-webpack-config');
3+
4+
const args = process.argv.slice(2);
5+
const isWatching = args.indexOf('-w') !== -1;
6+
7+
const webpackConfig = getWebpackConfig();
8+
9+
if (isWatching) {
10+
webpack(webpackConfig).watch({}, () => {});
11+
} else {
12+
webpack(webpackConfig, () => {});
13+
}

‎bin/get-webpack-config.js

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
4+
// Plugins
5+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
6+
const HtmlWebpackPlugin = require('html-webpack-plugin');
7+
8+
const rootPath = path.join(__dirname, '..');
9+
10+
module.exports = ({ isProd = false, isWebpackDevServer = false, port } = {}) => ({
11+
devtool: 'source-map',
12+
entry: {
13+
[`app${isProd ? '.min' : ''}`]: (
14+
isWebpackDevServer ? [`webpack-dev-server/client?http://localhost:${port}`, 'webpack/hot/dev-server'] : []
15+
).concat(path.join(rootPath, 'src', 'index.js'))
16+
},
17+
output: {
18+
path: path.join(rootPath, 'dist'),
19+
filename: '[name].js',
20+
publicPath: ''
21+
},
22+
plugins: [
23+
new ExtractTextPlugin({
24+
filename: '[name].css',
25+
disable: isWebpackDevServer,
26+
allChunks: true
27+
}),
28+
new webpack.DefinePlugin({
29+
__PROD__: JSON.stringify(isProd),
30+
__DEV__: JSON.stringify(!isProd),
31+
__DEVSERVER__: JSON.stringify(isWebpackDevServer),
32+
'process.env': {
33+
NODE_ENV: JSON.stringify(isProd ? 'production' : 'development')
34+
}
35+
}),
36+
new HtmlWebpackPlugin({
37+
minify: {},
38+
template: path.join(rootPath, 'src', 'index.html'),
39+
inject: 'head'
40+
}),
41+
new webpack.ProvidePlugin({
42+
fetch: 'imports?this=>global!exports?global.fetch!whatwg-fetch'
43+
})
44+
]
45+
.concat(isWebpackDevServer ? [
46+
new webpack.HotModuleReplacementPlugin()
47+
] : [])
48+
.concat(isProd ? [
49+
new webpack.optimize.UglifyJsPlugin({
50+
output: {
51+
comments: false
52+
}
53+
})
54+
] : []),
55+
module: {
56+
rules: [
57+
{
58+
test: /\.js$/,
59+
exclude: /node_modules/,
60+
use: [
61+
{
62+
loader: 'babel-loader',
63+
options: {
64+
presets: ['es2015', 'stage-2']
65+
}
66+
}
67+
]
68+
},
69+
{
70+
test: /\.jsx$/,
71+
exclude: /node_modules/,
72+
use: [
73+
{
74+
loader: 'babel-loader',
75+
options: {
76+
presets: ['es2015', 'stage-2', 'react'].concat(isWebpackDevServer ? ['react-hmre'] : [])
77+
}
78+
}
79+
]
80+
}, {
81+
test: /\.css$/,
82+
use: [
83+
ExtractTextPlugin.extract({
84+
loader: 'to-string-loader',
85+
fallbackLoader: 'style-loader'
86+
}),
87+
{
88+
loader: 'css-loader'
89+
}
90+
]
91+
}, {
92+
test: /\.woff(2)?$/,
93+
use: [
94+
{
95+
loader: 'url-loader',
96+
options: {
97+
limit: 10000,
98+
name: './font/[hash].[ext]',
99+
mimetype: 'application/font-woff'
100+
}
101+
}
102+
]
103+
}, {
104+
test: /\.(ttf|eot|svg)$/,
105+
use: [
106+
{
107+
loader: 'url-loader',
108+
options: {
109+
limit: 10000,
110+
name: './font/[hash].[ext]'
111+
}
112+
}
113+
]
114+
}, {
115+
test: /\.(gif|png)$/,
116+
use: [
117+
{
118+
loader: 'url-loader',
119+
options: {
120+
limit: 10000,
121+
name: './asset/[hash].[ext]'
122+
}
123+
}
124+
]
125+
}
126+
]
127+
},
128+
resolve: {
129+
modules: [
130+
rootPath,
131+
path.join(rootPath, 'node_modules')
132+
]
133+
}
134+
});

‎bin/start.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const getWebpackConfig = require('./get-webpack-config');
2+
const webpack = require('webpack');
3+
const WebpackDevServer = require('webpack-dev-server');
4+
5+
const args = process.argv.slice(2);
6+
const isProd = args.indexOf('-p') !== -1;
7+
const port = 8080;
8+
9+
const webpackConfig = getWebpackConfig({
10+
isWebpackDevServer: true,
11+
isProd,
12+
port
13+
});
14+
15+
const server = new WebpackDevServer(webpack(webpackConfig), {
16+
stats: {
17+
colors: true
18+
},
19+
hot: true
20+
});
21+
22+
server.listen(port, '0.0.0.0', () => {
23+
console.log(`Listening at localhost:${port}`);
24+
});

‎bin/test.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const path = require('path');
2+
const getWebpackConfig = require('./get-webpack-config');
3+
const Server = require('karma').Server;
4+
5+
// MODE const
6+
const MODE = {
7+
default: 0,
8+
coverage: 1,
9+
coverageToLcov: 2
10+
};
11+
12+
const rootPath = path.join(__dirname, '..');
13+
const testBundles = [
14+
path.join(rootPath, 'test', 'index.js')
15+
];
16+
const coveragePaths = [
17+
path.join(rootPath, 'src')
18+
];
19+
const port = 9876;
20+
21+
const args = process.argv.slice(2);
22+
let mode = MODE.default;
23+
if (args.indexOf('-coverage') !== -1) {
24+
mode = MODE.coverage;
25+
} else if (args.indexOf('-coverageToLcov') !== -1) {
26+
mode = MODE.coverageToLcov;
27+
}
28+
29+
const isWatching = args.indexOf('-w') !== -1;
30+
31+
const server = new Server({
32+
// ... normal karma configuration
33+
port,
34+
browsers: ['PhantomJS'],
35+
singleRun: !isWatching,
36+
files: [
37+
'node_modules/babel-polyfill/dist/polyfill.js'
38+
].concat(testBundles),
39+
preprocessors: [].concat(testBundles).reduce((obj, file) => (
40+
Object.assign(obj, {
41+
[file]: ['webpack', 'sourcemap']
42+
})
43+
), {}),
44+
plugins: ['karma-webpack', 'karma-jasmine', 'karma-nyan-reporter', 'karma-coverage', 'karma-sourcemap-loader', 'karma-phantomjs-launcher', 'karma-phantomjs-shim'],
45+
frameworks: ['phantomjs-shim', 'jasmine'],
46+
reporters: [
47+
mode === MODE.coverageToLcov ? 'dots' : 'nyan' // Usually running in ci to produce lcov for coveralls, nyan is annoying in ci log
48+
].concat(
49+
[MODE.coverage, MODE.coverageToLcov].indexOf(mode) !== -1 ? ['coverage'] : []
50+
),
51+
// reporter options
52+
nyanReporter: {
53+
suppressErrorHighlighting: true
54+
},
55+
coverageReporter: {
56+
dir: 'coverage/',
57+
reporters: [{
58+
type: mode === MODE.coverageToLcov ? 'lcov' : 'html', // lcov or lcovonly are required for generating lcov.info files, html for local coverage report
59+
subdir: '.'
60+
}]
61+
},
62+
webpack: getWebpackConfig({
63+
isTest: true,
64+
coveragePaths
65+
}),
66+
webpackMiddleware: {
67+
noInfo: true
68+
}
69+
});
70+
71+
server.start();

‎bin/webpack-eslint.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const getWebpackConfig = require('./get-webpack-config');
2+
3+
module.exports = {
4+
globals: {
5+
__DEV__: false,
6+
__PROD__: false,
7+
__DEVSERVER__: false,
8+
'process.env.NODE_ENV': false
9+
},
10+
settings: {
11+
'import/resolver': {
12+
webpack: {
13+
config: getWebpackConfig()
14+
}
15+
}
16+
}
17+
};

‎bin/webpack.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const getWebpackConfig = require('./get-webpack-config.js');
2+
3+
const args = process.argv.slice(2);
4+
const isProd = args.indexOf('-p') !== -1;
5+
6+
module.exports = getWebpackConfig({ isProd });

‎karma.conf.js

-30
This file was deleted.

‎package.json

+29-33
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
"__PROD__": {
3232
"__SSR__": true,
3333
"__DEVTOOLS__": false
34-
},
35-
"__CORDOVA__": {
36-
"__SSR__": true,
37-
"__DEVTOOLS__": true
3834
}
3935
},
4036
"homepage": "https://github.com/unimonkiez/react-cordova-boilerplate#readme",
@@ -43,65 +39,65 @@
4339
"autoprefixer": "^6.3.7",
4440
"autoprefixer-loader": "^3.2.0",
4541
"babel-core": "^6.11.4",
46-
"babel-eslint": "^6.1.2",
42+
"babel-eslint": "^7.1.1",
4743
"babel-loader": "^6.2.4",
4844
"babel-preset-es2015": "^6.9.0",
4945
"babel-preset-react": "^6.11.1",
5046
"babel-preset-react-hmre": "^1.1.1",
51-
"babel-preset-stage-0": "^6.5.0",
52-
"babel-runtime": "^6.9.2",
53-
"classnames": "^2.2.5",
54-
"cross-env": "^2.0.0",
55-
"css-loader": "^0.23.1",
47+
"babel-preset-stage-2": "^6.18.0",
48+
"css-loader": "^0.26.1",
5649
"deasync": "^0.1.7",
57-
"eslint": "^2.13.1",
58-
"eslint-config-airbnb": "^9.0.1",
50+
"eslint": "^3.13.1",
51+
"eslint-config-airbnb": "^14.0.0",
52+
"eslint-import-resolver-webpack": "^0.8.0",
5953
"eslint-loader": "^1.4.1",
60-
"eslint-plugin-import": "^1.12.0",
61-
"eslint-plugin-jsx-a11y": "^1.5.5",
62-
"eslint-plugin-react": "^5.2.2",
63-
"extract-text-webpack-plugin": "^1.0.1",
54+
"eslint-plugin-import": "^2.2.0",
55+
"eslint-plugin-jsx-a11y": "^3.0.2",
56+
"eslint-plugin-react": "^6.9.0",
57+
"extract-text-webpack-plugin": "^2.0.0-beta.5",
6458
"file-loader": "^0.9.0",
6559
"html-webpack-plugin": "^2.22.0",
66-
"imports-loader": "^0.6.5",
60+
"imports-loader": "^0.7.0",
6761
"install": "^0.8.1",
6862
"jasmine": "^2.4.1",
6963
"jasmine-core": "^2.4.1",
7064
"karma": "^1.1.2",
65+
"karma-coverage": "^1.1.1",
7166
"karma-jasmine": "^1.0.2",
67+
"karma-nyan-reporter": "^0.2.5",
7268
"karma-phantomjs-launcher": "^1.0.1",
7369
"karma-phantomjs-shim": "^1.4.0",
74-
"karma-webpack": "^1.7.0",
75-
"memory-fs": "^0.3.0",
76-
"node-libs-browser": "^1.0.0",
77-
"node-sass": "^3.8.0",
70+
"karma-sourcemap-loader": "^0.3.7",
71+
"karma-webpack": "^2.0.1",
72+
"memory-fs": "^0.4.1",
73+
"node-sass": "^4.3.0",
7874
"phantomjs": "^2.1.7",
7975
"radium": "^0.18.1",
80-
"raw-loader": "^0.5.1",
8176
"react": "^15.2.1",
8277
"react-dom": "^15.2.1",
83-
"react-redux": "^4.4.5",
84-
"react-router": "^2.6.0",
78+
"react-redux": "^5.0.2",
79+
"react-router": "^3.0.1",
8580
"redux": "^3.5.2",
8681
"redux-devtools": "^3.3.1",
8782
"redux-devtools-dock-monitor": "^1.1.1",
8883
"redux-devtools-log-monitor": "^1.0.11",
8984
"require-from-string": "^1.2.0",
9085
"sass-loader": "^4.0.0",
9186
"style-loader": "^0.13.1",
87+
"to-string-loader": "^1.1.5",
9288
"url-loader": "^0.5.7",
9389
"webpack": "^1.13.1",
9490
"webpack-dev-server": "^1.14.1"
9591
},
9692
"scripts": {
97-
"build": "webpack --progress",
98-
"build:prod": "cross-env NODE_ENV=production npm run build",
99-
"build:cordova": "cross-env NODE_ENV=production cross-env BUILD_TARGET=cordova npm run build",
100-
"start": "webpack-dev-server --port 3000 --host 0.0.0.0 --inline --hot --progress --colors ",
101-
"start:prod": "cross-env NODE_ENV=production npm run start",
102-
"lint": "eslint --ext .js,.jsx .",
103-
"test": "cross-env NODE_ENV=production karma start",
104-
"predeploy": "npm run build:cordova",
105-
"deploy": "git add -f www/ && node ./bin/bump.js && git checkout gh-pages && git merge master && git checkout master && git push --tags && npm publish && git push origin master gh-pages"
93+
"build": "node ./bin/build.js",
94+
"build:prod": "npm run build -- -p",
95+
"build:cordova": "npm run build:prod -- -c",
96+
"start": "node ./bin/start.js",
97+
"start:prod": "node ./bin/start.js -- -p",
98+
"lint": "eslint --fix --ext .js,.jsx .",
99+
"test": "node ./bin/test.js",
100+
"preupdate-demo": "npm run build",
101+
"update-demo": "git add -f www/ && node ./bin/bump.js && git checkout gh-pages && git merge master && git checkout master && git push --tags && npm publish && git push origin master gh-pages"
106102
}
107103
}

‎src/.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ecmaFeatures": {
88
"modules": true
99
},
10+
"extends": "../bin/webpack-eslint.js",
1011
"rules": {
1112
"strict": [2, "never"]
1213
}

‎src/__tests__/.eslintrc

-6
This file was deleted.

‎test/.eslintrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"node": false,
5+
"jasmine": true
6+
},
7+
"ecmaFeatures": {
8+
"modules": true
9+
},
10+
"extends": "../bin/webpack-eslint.js",
11+
"rules": {
12+
"strict": [2, "never"]
13+
}
14+
}

‎test/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Disabling `no-undef` because we are using here require.context which requires files dynamically, instead of regular ES6 imports
2+
/* eslint-disable no-undef */
3+
4+
// load all specs into one bundle
5+
const testsContext = require.context('./spec/', true, /\.spec\.jsx?$/);
6+
testsContext.keys().forEach(testsContext);
7+
8+
// require all `src/**/*.js`
9+
const componentsContext = require.context('../src/', true, /\.jsx?$/);
10+
componentsContext.keys().forEach(componentsContext);
11+
12+
/* eslint-enable no-undef */
File renamed without changes.

‎yarn.lock

+5,838
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.