Skip to content
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

Issue 18/migrate to webpack 2 #22

Closed
wants to merge 10 commits into from
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# http://editorconfig.org

# A special property that should be specified at the top of the file outside of
# any sections. Set to true to stop .editor config file search on current file
root = true

[*]
# Indentation style
# Possible values - tab, space
indent_style = space

# Indentation size in single-spaced characters
# Possible values - an integer, tab
indent_size = 2

# Line ending file format
# Possible values - lf, crlf, cr
end_of_line = lf

# File character encoding
# Possible values - latin1, utf-8, utf-16be, utf-16le
charset = utf-8

# Denotes whether to trim whitespace at the end of lines
# Possible values - true, false
trim_trailing_whitespace = true

# Denotes whether file should end with a newline
# Possible values - true, false
insert_final_newline = true
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage/**
node_modules/**
dist/**
src/index.html
40 changes: 40 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"parser": "babel-eslint",
"extends": [
"standard"
],
"plugins": [
"babel",
"promise"
],
"env": {
"browser": true
},
"globals": {
"__DEV__": false,
"__TEST__": false,
"__PROD__": false,
"__COVERAGE__": false,
"__STYLEGUIDE__": false
},
"rules": {
"key-spacing": 0,
"jsx-quotes": [
2,
"prefer-single"
],
"max-len": [
2,
120,
2
],
"object-curly-spacing": [
2,
"always"
],
"semi": [
"error",
"always"
]
}
}
16 changes: 16 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"asi": true,
"camelcase": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"quotmark": "single",
"strict": false,

"esversion": 6,
"globalstrict": true,

"browser": true,
"node": true
}
22 changes: 11 additions & 11 deletions bin/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const webpackCompiler = (webpackConfig) =>
compiler.run((err, stats) => {
if (err) {
debug('Webpack compiler encountered a fatal error.', err);
return reject(err)
return reject(err);
}

const jsonStats = stats.toJson();
Expand All @@ -24,16 +24,16 @@ const webpackCompiler = (webpackConfig) =>
if (jsonStats.errors.length > 0) {
debug('Webpack compiler encountered errors.');
debug(jsonStats.errors.join('\n'));
return reject(new Error('Webpack compiler encountered errors'))
return reject(new Error('Webpack compiler encountered errors'));
} else if (jsonStats.warnings.length > 0) {
debug('Webpack compiler encountered warnings.');
debug(jsonStats.warnings.join('\n'))
debug(jsonStats.warnings.join('\n'));
} else {
debug('No errors or warnings encountered.')
debug('No errors or warnings encountered.');
}

resolve(jsonStats)
})
resolve(jsonStats);
});
});

// This is the application compiler. It runs the webpackCompiler above,
Expand All @@ -44,18 +44,18 @@ const compile = () => {
.then(() => webpackCompiler(webpackConfig))
.then(stats => {
if (stats.warnings.length && project.compiler_fail_on_warning) {
throw new Error('Config set to fail on warning, exiting with status code "1".')
throw new Error('Config set to fail on warning, exiting with status code "1".');
}
debug('Copying static assets to dist folder.');
fs.copySync(project.paths.public(), project.paths.dist())
fs.copySync(project.paths.public(), project.paths.dist());
})
.then(() => {
debug('Compilation completed successfully.')
debug('Compilation completed successfully.');
})
.catch((err) => {
debug('Compiler encountered an error.', err);
process.exit(1)
})
process.exit(1);
});
};

compile();
4 changes: 2 additions & 2 deletions config/environments.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module.exports = {
compiler_public_path : '/',
compiler_fail_on_warning : false,
compiler_hash_type : 'chunkhash',
compiler_devtool : null,
compiler_devtool : false,
compiler_stats : {
chunks : true,
chunkModules : true,
colors : true
}
})
}
};
115 changes: 58 additions & 57 deletions config/karma.config.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
const argv = require('yargs').argv
const project = require('./project.config')
const webpackConfig = require('./webpack.config')
const debug = require('debug')('app:config:karma')
const argv = require('yargs').argv;
const project = require('./project.config');
const webpackConfig = require('./webpack.config');
const debug = require('debug')('app:config:karma');

debug('Creating configuration.')
debug('Creating configuration.');
const karmaConfig = {
basePath : '../', // project root in relation to bin/karma.js
files : [
basePath: '../', // project root in relation to bin/karma.js
files: [
{
pattern: `./${project.dir_test}/test-bundler.js`,
watched: false,
served: true,
included: true
}
],
singleRun: !argv.watch,
frameworks: ['mocha'],
reporters: ['mocha'],
preprocessors: {
[`${project.dir_test}/test-bundler.js`] : ['webpack']
},
browsers: ['PhantomJS'],
webpack: {
entry: webpackConfig.entry,
devtool: 'cheap-module-source-map',
resolve: Object.assign({}, webpackConfig.resolve, {
alias: Object.assign({}, webpackConfig.resolve.alias, {
sinon: 'sinon/pkg/sinon.js'
})
}),
plugins: webpackConfig.plugins,
module: {
noParse: [
/\/sinon\.js/
],
rules: webpackConfig.module.rules.concat([
{
pattern : `./${project.dir_test}/test-bundler.js`,
watched : false,
served : true,
included : true
test: /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
loader: 'imports-loader?define=>false,require=>false'
}
],
singleRun : !argv.watch,
frameworks : ['mocha'],
reporters : ['mocha'],
preprocessors : {
[`${project.dir_test}/test-bundler.js`] : ['webpack']
},
browsers : ['PhantomJS'],
webpack : {
devtool : 'cheap-module-source-map',
resolve : Object.assign({}, webpackConfig.resolve, {
alias : Object.assign({}, webpackConfig.resolve.alias, {
sinon : 'sinon/pkg/sinon.js'
})
}),
plugins : webpackConfig.plugins,
module : {
noParse : [
/\/sinon\.js/
],
loaders : webpackConfig.module.loaders.concat([
{
test : /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
loader : 'imports?define=>false,require=>false'
}
])
},
sassLoader : webpackConfig.sassLoader
},
webpackMiddleware : {
noInfo : true
},
coverageReporter : {
reporters : project.coverage_reporters
])
}
}
},
webpackMiddleware: {
noInfo: true
},
coverageReporter: {
reporters: project.coverage_reporters
}
};

if (project.globals.__COVERAGE__) {
karmaConfig.reporters.push('coverage')
karmaConfig.webpack.module.preLoaders = [{
test : /\.(js|jsx)$/,
include : new RegExp(project.dir_client),
exclude : /node_modules/,
loader : 'babel',
query : Object.assign({}, project.compiler_babel, {
plugins : (project.compiler_babel.plugins || []).concat('istanbul')
})
}]
karmaConfig.reporters.push('coverage');
karmaConfig.webpack.module.rules.push({
test: /\.(js|jsx)$/,
enforce: 'pre',
include: new RegExp(project.dir_client),
exclude: /node_modules/,
loader: 'babel-loader',
options: Object.assign({}, project.compiler_babel, {
plugins: (project.compiler_babel.plugins || []).concat('istanbul')
})
});
}

module.exports = (cfg) => cfg.set(karmaConfig)
module.exports = (cfg) => cfg.set(karmaConfig);
8 changes: 4 additions & 4 deletions config/project.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ config.compiler_vendors = config.compiler_vendors
`Package "${dep}" was not found as an npm dependency in package.json; ` +
`it won't be included in the webpack vendor bundle.
Consider removing it from \`compiler_vendors\` in ~/config/index.js`
)
);
});

// ------------------------------------
// Utilities
// ------------------------------------
function base () {
const args = [config.path_base].concat([].slice.call(arguments));
return path.resolve.apply(path, args)
return path.resolve.apply(path, args);
}

config.paths = {
Expand All @@ -157,9 +157,9 @@ const environments = require('./environments.config');
const overrides = environments[config.env];
if (overrides) {
debug('Found overrides, applying to default configuration.');
Object.assign(config, overrides(config))
Object.assign(config, overrides(config));
} else {
debug('No environment overrides found, defaults will be used.')
debug('No environment overrides found, defaults will be used.');
}

module.exports = config;
Loading