Skip to content

Commit

Permalink
Redo the template project, simplify it
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbruegge committed Oct 6, 2018
1 parent 4bfe0bd commit f856f8e
Show file tree
Hide file tree
Showing 19 changed files with 9,420 additions and 16,602 deletions.
80 changes: 25 additions & 55 deletions configs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const {
createConfig,
defineConstants,
match,
env,
defineConstants,
entryPoint,
setOutput,
sourceMaps,
addPlugins,
devServer,
postcss,
sass,
css,
typescript,
extractText,
customConfig,
uglify,
match,
file,
url,
resolve
} = require('webpack-blocks');
const webpackMerge = require('webpack-merge');
resolve,
setMode
} = require('@webpack-blocks/webpack');
const { css, file, url } = require('@webpack-blocks/assets');
const devServer = require('@webpack-blocks/dev-server');
const extractText = require('@webpack-blocks/extract-text');
const postcss = require('@webpack-blocks/postcss');
const sass = require('@webpack-blocks/sass');
const uglify = require('@webpack-blocks/uglify');
const typescript = require('@webpack-blocks/typescript');
const tslint = require('@webpack-blocks/tslint');

const webpackMerge = require('webpack-merge');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
Expand All @@ -34,54 +34,27 @@ const fs = require('fs');
const appPath = (...names) => path.join(process.cwd(), ...names);
const userConfig = require(appPath('webpack.config.js'));

const preprocessor = production => ({
PRODUCTION: production,
DEVELOPMENT: !production
});

const ifdef = config => (context, { addLoader }) =>
addLoader(
Object.assign(
{
test: /\.tsx?/,
use: [
{
loader: 'awesome-typescript-loader'
},
{ loader: 'ifdef-loader?' + JSON.stringify(config) }
]
},
context.match
)
);

const makeTs = prod =>
match(
['*.js', '*.jsx', '*.ts', '*.tsx'],
[
ifdef(preprocessor(prod)),
typescript({
useCache: true,
cacheDirectory: 'node_modules/.cache/at-loader'
})
]
);

module.exports = webpackMerge(
createConfig([
setMode(process.env.NODE_ENV || 'development'),
typescript({
useCache: true,
cacheDirectory: 'node_modules/.cache/at-loader'
}),
tslint(),
resolve({ extensions: ['.js', '.jsx'] }),
match(
['*.scss', '*.sass'],
[
postcss({
plugins: [autoprefixer({ browsers: ['last 2 versions'] })]
}),
sass({
includePaths: [appPath('node_modules')],
sourceMap: true
}),
env('production', [extractText('[name].[contenthash:8].css')])
postcss({
plugins: [autoprefixer({ browsers: ['last 2 versions'] })]
}),

env('production', [extractText('[name].[hash].css')])
]
),
match(['*.eot', '*.ttf', '*.woff', '*.woff2'], [file()]),
Expand All @@ -108,15 +81,13 @@ module.exports = webpackMerge(
})
]),
env('development', [
makeTs(false),
devServer({
contentBase: appPath('public')
}),
sourceMaps(),
addPlugins([new webpack.NamedModulesPlugin()])
]),
env('production', [
makeTs(true),
uglify({
parallel: true,
cache: true,
Expand All @@ -132,8 +103,7 @@ module.exports = webpackMerge(
}),
new CopyWebpackPlugin([{ from: 'public', to: '' }])
])
]),
env('test', [makeTs(true)])
])
]),
userConfig
);
30 changes: 0 additions & 30 deletions configs/webpack.config.test.js

This file was deleted.

15 changes: 0 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,7 @@ const script = process.argv[2];
const args = process.argv.slice(3);
const path = require('path');

function rimraf() {
const exectuable = path.join(
process.cwd(),
'node_modules',
'.bin',
'rimraf'
);
spawn.sync(exectuable, ['build', '.tmp', '.nyc_output', 'coverage'], {
stdio: 'inherit'
});
}

switch (script) {
case 'clean':
rimraf();
break;
case 'start':
case 'test':
case 'build':
Expand Down
Loading

0 comments on commit f856f8e

Please sign in to comment.