Skip to content

Commit bf9cc9a

Browse files
committed
feat(webpack): merge es2016 and typescript skeletons
1 parent f52ba71 commit bf9cc9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+393
-280
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ This library is part of the [Aurelia](http://www.aurelia.io/) platform and provi
1111

1212
Please see the individual readme file within each skeleton for an explanation of how to get setup.
1313

14-
* **skeleton-es2016-webpack** - This project is configured to use the Babel transpiler so that you can write your application in ES 2016 code. It should work well with any standard text editor. This skeleton uses NPM for package management and Webpack for bundling.
14+
* **skeleton-webpack** - This project is configured to use either the Babel or the TypeScript transpiler so that you can write your application using either language. It should work well with any standard text editor. This skeleton uses NPM for package management and Webpack for bundling.
1515
* **skeleton-es2016** - This project is configured to use the Babel transpiler so that you can write your application in ES 2016 code. It should work well with any standard text editor. This skeleton uses JSPM for package management and SystemJS for loading and bundling.
16-
* **skeleton-typescript-webpack** - This project is configured to use the TypeScript transpiler so that you can write your application using TypeScript. It should work well with any standard text editor. This skeleton uses NPM for package management and Webpack for bundling.
1716
* **skeleton-typescript** - This project is configured to use the TypeScript transpiler so that you can write your application using TypeScript. It should work well with any standard text editor, however it has been specially configured to work well with VSCode and Atom, including full TypeScript intellisense for app, unit test and e2e test code. This skeleton uses JSPM for package management and SystemJS for loading and bundling.
1817
* **skeleton-typescript-aspnetcore** - This is an ASP.NET Core web project configured for building a .NET backend and an Aurelia front-end. It is configured for full TypeScript support, similar to the standard skeleton-typescript option. This skeleton uses JSPM for package management and SystemJS for loading and bundling.
1918
* **skeleton-es2016-aspnetcore** - This is an ASP.NET Core web project pre-configured for building a .NET backend and an Aurelia front-end. It is configured for full ES 2016 support with Babel, similar to the standard skeleton-es2016 option. This skeleton uses JSPM for package management and SystemJS for loading and bundling.

skeleton-typescript-webpack/.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./node_modules/aurelia-tools/.eslintrc.json",
3+
"rules": {
4+
"no-alert": 0,
5+
"consistent-return": 0
6+
}
7+
}

skeleton-typescript-webpack/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# aurelia-skeleton-typescript-webpack
1+
# aurelia-skeleton-webpack
22

33
## Getting started
44

skeleton-typescript-webpack/config/helpers.js

+33-13
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
* https://github.com/AngularClass/angular2-webpack-starter
44
*/
55

6-
var path = require('path');
6+
const path = require('path');
7+
const fs = require('fs');
78

89
// Helper functions
9-
var ROOT = path.resolve(__dirname, '..');
10+
const ROOT = path.resolve(__dirname, '..');
11+
const jsonfile = require('jsonfile');
12+
const del = require('del');
1013

11-
var jsonfile = require('jsonfile');
12-
13-
console.log('root directory:', root() + '\n');
14+
const pkg = JSON.parse(fs.readFileSync(root('package.json')));
15+
const language = (pkg.language || 'javascript').toLowerCase();
16+
const readdir = require('recursive-readdir-sync');
17+
const moduleType = 'es2015'; // in case of weird problems try 'commonjs'; uncompressed bundle will be ~35KB larger
1418

1519
function hasProcessFlag(flag) {
1620
return process.argv.join('').indexOf(flag) > -1;
@@ -21,15 +25,28 @@ function root(args) {
2125
return path.join.apply(path, [ROOT].concat(args));
2226
}
2327

24-
const fileSystem = require('fs');
25-
const readdir = require('recursive-readdir-sync');
26-
const moduleType = 'es2015'; // or in case of problems try 'commonjs'; bundle will be ~35KB larger
28+
function selectLanguage(target) {
29+
if (!!pkg.language) {
30+
throw new Error('You have previously selected a language. If you know what you\'re doing, do the change manually in package.json.');
31+
}
32+
target = target.toLowerCase();
33+
if (target != 'typescript' && target != 'javascript') {
34+
throw new Error('Available languages are: typescript or javascript');
35+
}
36+
37+
fs.renameSync(root(target + '-src'), root('src'));
38+
fs.renameSync(root(target + '-test'), root('test'));
39+
const other = target === 'typescript' ? 'javascript' : 'typescript';
40+
del.sync([root(other + '-src/**'), root(other + '-test/**')]);
41+
pkg.language = target;
42+
jsonfile.writeFileSync(root('package.json'), pkg, {spaces: 2});
43+
return true;
44+
}
2745

2846
function generateMeta(input) {
2947
var aureliaPackages = input.aurelia;
3048
var bootstrapPackages = input.bootstrap;
3149
var excludeFromAureliaBundle = input.excludeFromAureliaBundle;
32-
var pkg = JSON.parse(fileSystem.readFileSync(root('package.json')));
3350
var packages = Object.keys(pkg.dependencies || {});
3451
packages = packages.concat(aureliaPackages.filter(item => packages.indexOf(item) < 0));
3552
var aliases = {};
@@ -38,7 +55,7 @@ function generateMeta(input) {
3855
packages.forEach(function (moduleId) {
3956
var vendorPath = path.resolve(root('node_modules'), moduleId);
4057
var vendorPkgPath = path.resolve(vendorPath, 'package.json');
41-
var vendorPkg = JSON.parse(fileSystem.readFileSync(vendorPkgPath, 'utf8'));
58+
var vendorPkg = JSON.parse(fs.readFileSync(vendorPkgPath, 'utf8'));
4259

4360
if (vendorPkg._npmUser && vendorPkg._npmUser.name === 'aureliaeffect' || aureliaPackages.indexOf(moduleId) >= 0) {
4461
// enable for es2015 builds:
@@ -66,6 +83,9 @@ function generateMeta(input) {
6683
return { aliases, vendorPackages, aureliaPackages, bootstrapPackages };
6784
}
6885

69-
exports.hasProcessFlag = hasProcessFlag;
70-
exports.root = root;
71-
exports.generateMeta = generateMeta;
86+
module.exports.hasProcessFlag = hasProcessFlag;
87+
module.exports.root = root;
88+
module.exports.generateMeta = generateMeta;
89+
module.exports.language = language;
90+
module.exports.selectLanguage = selectLanguage;
91+
module.exports.package = pkg;

skeleton-typescript-webpack/config/karma.conf.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* https://github.com/AngularClass/angular2-webpack-starter
44
*/
55

6+
import testWebpackConfig from './webpack.test';
7+
68
module.exports = function(config) {
7-
var testWebpackConfig = require('./webpack.test.js');
9+
// var testWebpackConfig = require('./webpack.test');
810

911
config.set({
1012

@@ -27,15 +29,15 @@ module.exports = function(config) {
2729
* we are building the test environment in ./spec-bundle.js
2830
*/
2931
files: [
30-
{ pattern: './config/spec-bundle.js', watched: false },
32+
{ pattern: './spec-bundle.js', watched: false },
3133
],
3234

3335
/*
3436
* preprocess matching files before serving them to the browser
3537
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3638
*/
3739
preprocessors: {
38-
'./config/spec-bundle.js': [/*'coverage', */'webpack', 'sourcemap']
40+
'./spec-bundle.js': [/*'coverage', */'webpack', 'sourcemap']
3941
},
4042

4143
// Webpack Config at ./webpack.test.js

skeleton-typescript-webpack/config/protractor.conf.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
require('ts-babel-node/register');
2-
var helpers = require('./helpers');
1+
const helpers = require('./helpers');
32

43
exports.config = {
54
baseUrl: 'http://localhost:3000/',
65

76
// use `npm run e2e`
87
specs: [
9-
helpers.root('test/e2e/src/**/*.ts')
8+
helpers.root(helpers.language === 'javascript' ? 'test/e2e/**/*.js' : 'test/e2e/**/*.ts')
109
],
1110
exclude: [],
1211

@@ -30,6 +29,14 @@ exports.config = {
3029
}
3130
},
3231

32+
onPrepare: function() {
33+
if (helpers.language === 'javascript') {
34+
require('babel-register');
35+
} else {
36+
require('ts-babel-node-extendable').register({ compilerOptions: { allowJs: false } });
37+
}
38+
},
39+
3340
/**
3441
* Aurelia configuration
3542
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const helpers = require('./helpers');
2+
3+
if (!!helpers.package.language) {
4+
const inquirer = require('inquirer');
5+
inquirer.prompt([
6+
{
7+
type: 'list',
8+
name: 'language',
9+
message: 'Which language would you like to use with Aurelia?',
10+
choices: [
11+
'JavaScript',
12+
'TypeScript'
13+
]
14+
}
15+
]).then(function (answers) {
16+
try {
17+
helpers.selectLanguage(answers.language);
18+
} catch (e) {
19+
console.error(e.message);
20+
}
21+
});
22+
}

skeleton-typescript-webpack/config/spec-bundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require('aurelia-pal-browser').initialize();
3030
* any file that ends with spec.js and get its path. By passing in true
3131
* we say do this recursively
3232
*/
33-
var testContext = require.context('../test/unit', true, /\.spec\.ts/);
33+
var testContext = require.context('../test/unit', true, /\.spec\.(ts|js)/);
3434

3535
/*
3636
* get all the files, for each file, call the context function

skeleton-typescript-webpack/config/webpack.base-dev.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ const METADATA = {
1414

1515
const config = {
1616
metadata: METADATA,
17+
1718
/**
1819
* Switch loaders to debug mode.
1920
*
2021
* See: http://webpack.github.io/docs/configuration.html#debug
2122
*/
2223
debug: true,
24+
2325
/**
2426
* Developer tool to enhance debugging
2527
*
2628
* See: http://webpack.github.io/docs/configuration.html#devtool
2729
* See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps
2830
*/
29-
devtool: 'eval',
30-
// devtool: 'cheap-module-eval-source-map',
31+
devtool: 'cheap-module-eval-source-map',
32+
// devtool: 'eval',
3133
// devtool: 'cheap-module-source-map',
3234
// devtool: 'eval-source-map',
3335

@@ -105,6 +107,11 @@ const config = {
105107
resourcePath: 'src'
106108
},
107109

110+
eslint: {
111+
emitError: false,
112+
configFile: helpers.root('.eslintrc')
113+
},
114+
108115
/**
109116
* Webpack Development Server configuration
110117
* Description: The webpack-dev-server is a little node.js Express server.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as helpers from './helpers';
2+
3+
const config = {
4+
module: {
5+
preLoaders: [
6+
/*
7+
* eslint loader support for *.js files
8+
*
9+
* See: https://github.com/MoOx/eslint-loader
10+
*/
11+
{ test: /\.js$/, loader: 'eslint', exclude: [ helpers.root('node_modules'), helpers.root('config'), helpers.root('index.js') ] }
12+
],
13+
loaders: [
14+
/*
15+
* Babel loader support for ES2015
16+
*
17+
* See: https://github.com/babel/babel-loader
18+
*/
19+
{
20+
test: /\.js$/,
21+
loader: 'babel',
22+
exclude: [/\.(spec|e2e)\.js$/, helpers.root('node_modules'), helpers.root('config')],
23+
query: {
24+
plugins: ['transform-decorators-legacy'],
25+
presets: ['es2015-loose-native-modules', 'stage-1'],
26+
cacheDirectory: true,
27+
}
28+
}
29+
]
30+
},
31+
plugins: []
32+
}
33+
34+
export default config;

skeleton-typescript-webpack/config/webpack.base-production.js

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ const config = {
138138
resourcePath: 'src'
139139
},
140140

141+
eslint: {
142+
emitError: true,
143+
configFile: helpers.root('.eslintrc')
144+
},
145+
141146
/**
142147
* Html loader advanced options
143148
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as helpers from './helpers';
2+
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
3+
4+
const config = {
5+
module: {
6+
preLoaders: [
7+
/*
8+
* Tslint loader support for *.ts files
9+
*
10+
* See: https://github.com/wbuchwalter/tslint-loader
11+
*/
12+
{ test: /\.ts$/, loader: 'tslint', exclude: [ helpers.root('node_modules'), helpers.root('config') ] }
13+
],
14+
loaders: [
15+
/*
16+
* Typescript loader support for .ts
17+
*
18+
* See: https://github.com/s-panferov/awesome-typescript-loader
19+
*/
20+
{
21+
test: /\.ts$/,
22+
loader: 'awesome-typescript',
23+
exclude: [/\.(spec|e2e|d)\.ts$/, /node_modules/, helpers.root('config')],
24+
query: {
25+
tsconfig: 'tsconfig.webpack.json'
26+
}
27+
}
28+
]
29+
},
30+
plugins: [
31+
32+
/*
33+
* Plugin: ForkCheckerPlugin
34+
* Description: Do type checking in a separate process, so webpack don't need to wait.
35+
*
36+
* See: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse
37+
*/
38+
new ForkCheckerPlugin()
39+
40+
]
41+
}
42+
43+
export default config;

skeleton-typescript-webpack/config/webpack.base-web.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const config = {
99
...base.module,
1010
loaders: [
1111
...base.module.loaders,
12-
/*
13-
* Raw loader support for *.css files
14-
* Returns file content as string
15-
*
16-
* See: https://github.com/webpack/raw-loader
17-
*/
12+
/**
13+
* Raw loader support for *.css files
14+
* Returns file content as string
15+
*
16+
* See: https://github.com/webpack/raw-loader
17+
*/
1818
{
1919
test: /\.css$/,
2020
loaders: ExtractTextPlugin.extract('style', 'css')
@@ -23,7 +23,7 @@ const config = {
2323
},
2424
plugins: [
2525
...base.plugins,
26-
/*
26+
/**
2727
* Plugin: HtmlWebpackPlugin
2828
* Description: Simplifies creation of HTML files to serve your webpack bundles.
2929
* This is especially useful for webpack bundles that include a hash in the filename
@@ -40,7 +40,7 @@ const config = {
4040
}
4141
}),
4242

43-
/*
43+
/**
4444
* Plugin: CommonsChunkPlugin
4545
* Description: Shares common code between the pages.
4646
* It identifies common modules and put them into a commons chunk.

0 commit comments

Comments
 (0)