Skip to content

Commit

Permalink
Feature/new root directory syntax (#1)
Browse files Browse the repository at this point in the history
* added project args to config

* Refactored configs to a single class and instance for env and path reasons

* Updated the ng serve command to respect the new  class instance 🔥
  • Loading branch information
TheLarkInn authored Jul 2, 2016
1 parent 6f77db5 commit d52fb7f
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 423 deletions.
8 changes: 4 additions & 4 deletions addon/ng2/blueprints/ng2/files/__path__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ require('zone.js/dist/sync-test');
// RxJS
require('rxjs/Rx');

var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');
let testing: any = require('@angular/core/testing');
let browser: any = require('@angular/platform-browser-dynamic/testing');

testing.setBaseTestProviders(
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
);

var testContext = require.context('../src', true, /\.spec\.ts/);
let testContext: any = require.context('../src', true, /\.spec\.ts/);

/*
* get all the files, for each file, call the context function
* that will require the file and load it up here. Context will
* loop and require those spec files here
*/
function requireAll(requireContext) {
function requireAll(requireContext: any) {
return requireContext.keys().map(requireContext);
}

Expand Down
25 changes: 18 additions & 7 deletions addon/ng2/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const win = require('ember-cli/lib/utilities/windows-admin');
// const Build = require('../tasks/build');
// const BuildWatch = require('../tasks/build-watch');

const WebpackBuild = require('../tasks/build-webpack');
const WebpackBuildWatch = require('../tasks/build-webpack-watch');
var WebpackBuild = require('../tasks/build-webpack');
var WebpackBuildWatch = require('../tasks/build-webpack-watch');

interface BuildOptions {
environment?: string;
Expand All @@ -31,11 +31,22 @@ module.exports = Command.extend({
{ name: 'm2', type: Boolean, default: false}
],

run: function(commandOptions: BuildOptions) {

let buildTask = commandOptions.watch ?
new WebpackBuildWatch() :
new WebpackBuild();
run: function (commandOptions: BuildOptions) {
var project = this.project;
var ui = this.ui;
var buildTask = commandOptions.watch ?
new WebpackBuildWatch({
cliProject: project,
ui: ui,
outputPath: commandOptions.outputPath,
environment: commandOptions.environment
}) :
new WebpackBuild({
cliProject: project,
ui: ui,
outputPath: commandOptions.outputPath,
environment: commandOptions.environment
});

console.log(buildTask);

Expand Down
1 change: 0 additions & 1 deletion addon/ng2/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module.exports = Command.extend({
}

const ServeWebpackTask = (require('../tasks/serve-webpack.ts'))
// var ServeTask = require('../tasks/serve');

var serve = new ServeWebpackTask({
ui: this.ui,
Expand Down
1 change: 1 addition & 0 deletions addon/ng2/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from './webpack-build-test';
export * from './webpack-build-production';
export * from './webpack-build-development';
export * from './webpack-build-utils';
export {getWebpackMaterialConfig, getWebpackMaterialE2EConfig} from './webpack-build-material2.ts';

export * from './webpack-karma-config';
163 changes: 82 additions & 81 deletions addon/ng2/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,93 @@
import * as webpack from 'webpack';
import {ngAppResolve} from './webpack-build-utils';

const path = require('path');
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DebugWebpackPlugin = require('debug-webpack-plugin');

export const webpackCommonConfig = {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.ts', '.js'],
root: ngAppResolve('./src')
},
context: path.resolve(__dirname, './'),
entry: {
main: [ngAppResolve('./src/main.ts')],
vendor: ngAppResolve('./src/vendor.ts'),
polyfills: ngAppResolve('./src/polyfills.ts')
},
output: {
path: ngAppResolve('./dist'),
filename: '[name].bundle.js'
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
ngAppResolve('node_modules/rxjs'),
ngAppResolve('node_modules/@angular'),
]
}
],
loaders: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
query: {
useWebpackText: true,
tsconfig: ngAppResolve('./src/tsconfig.json'),
// resolveGlobs: false,
module: "es2015",
target: "es5",
lib: ['es6', 'dom'],
useForkChecker: true
export const getWebpackCommonConfig = function(projectRoot: string) {
return {
devtool: 'inline-source-map',
resolve: {
extensions: ['', '.ts', '.js'],
root: path.resolve(projectRoot, './src')
},
context: path.resolve(__dirname, './'),
entry: {
main: [path.resolve(projectRoot, './src/main.ts')],
vendor: path.resolve(projectRoot, './src/vendor.ts'),
polyfills: path.resolve(projectRoot, './src/polyfills.ts')
},
output: {
path: path.resolve(projectRoot, './dist'),
filename: '[name].bundle.js'
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'source-map-loader',
exclude: [
path.resolve(projectRoot, 'node_modules/rxjs'),
path.resolve(projectRoot, 'node_modules/@angular'),
]
}
],
loaders: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
query: {
useWebpackText: true,
tsconfig: path.resolve(projectRoot, './src/tsconfig.json'),
// resolveGlobs: false,
module: "es2015",
target: "es5",
lib: ['es6', 'dom'],
useForkChecker: true
}
},
{
loader: 'angular2-template-loader'
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{ test: /\.json$/, loader: 'json-loader'},
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
{ test: /\.html$/, loader: 'raw-loader' }
]
},
plugins: [
new ForkCheckerPlugin(),
new HtmlWebpackPlugin({
template: ngAppResolve('src/index.html'),
chunksSortMode: 'dependency'
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['polyfills', 'vendor'].reverse()
}),
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline',
filename: 'inline.js',
sourceMapFilename: 'inline.map'
}),
new CopyWebpackPlugin([{from: ngAppResolve('./public'), to: ngAppResolve('./dist/public')}])
],
node: {
global: 'window',
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{ test: /\.json$/, loader: 'json-loader'},
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
{ test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
{ test: /\.html$/, loader: 'raw-loader' }
]
},
plugins: [
new ForkCheckerPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(projectRoot, 'src/index.html'),
chunksSortMode: 'dependency'
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['polyfills', 'vendor'].reverse()
}),
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline',
filename: 'inline.js',
sourceMapFilename: 'inline.map'
}),
new CopyWebpackPlugin([{from: path.resolve(projectRoot, './public'), to: path.resolve(projectRoot, './dist/public')}])
],
node: {
global: 'window',
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
}
};
58 changes: 25 additions & 33 deletions addon/ng2/models/webpack-build-development.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
import { webpackCommonConfig } from '../models';
import { webpackMaterialConfig, webpackMaterialE2EConfig } from './webpack-build-material2';
import { ngAppResolve } from './webpack-build-utils';
const path = require('path')

const webpackMerge = require('webpack-merge');

const devConfigPartial = {
debug: true,
devtool: 'cheap-module-source-map',
output: {
path: ngAppResolve('./dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
},
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: ngAppResolve('./src')
},
node: {
global: 'window',
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false
}
export const getWebpackDevConfigPartial = function(projectRoot: string) {
return {
debug: true,
devtool: 'cheap-module-source-map',
output: {
path: path.resolve(projectRoot, './dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
},
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: path.resolve(projectRoot, './src')
},
node: {
global: 'window',
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false
}
};
}

export const webpackDevConfig = webpackMerge(webpackCommonConfig, devConfigPartial);

export const webpackDevMaterialConfig = webpackMerge(webpackMaterialConfig, devConfigPartial);

export const webpackDevMaterialE2EConfig = webpackMerge(webpackMaterialE2EConfig, devConfigPartial);
Loading

0 comments on commit d52fb7f

Please sign in to comment.