Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 5bf2100

Browse files
committed
🚧 webtasker
1 parent 01c102c commit 5bf2100

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

‎webtasker.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { task, series, parallel, clone, merge, shell } from 'webtasker';
2+
import * as webpack from 'webpack';
3+
import * as WebpackDevServer from 'webpack-dev-server';
4+
import * as path from 'path';
5+
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
6+
import * as PrerenderSpaPlugin from 'prerender-spa-plugin';
7+
import { TsConfigPathsPlugin, CheckerPlugin } from 'awesome-typescript-loader';
8+
9+
const CONFIG = {
10+
entry: {
11+
'index': './src/app/index'
12+
},
13+
output: {
14+
path: path.join(__dirname, 'dist'),
15+
filename: '[name].js',
16+
libraryExport: 'main',
17+
libraryTarget: 'var',
18+
library: 'beyond'
19+
},
20+
21+
resolve: {
22+
extensions: ['.ts', '.json', '.js']
23+
},
24+
target: 'web',
25+
node: false,
26+
module: {
27+
strictThisContextOnImports: true,
28+
rules: [
29+
{
30+
test: /\.tsx?$/,
31+
loader: 'awesome-typescript-loader',
32+
options: {
33+
configFileName: 'tsconfig.webpack.json',
34+
useCache: false
35+
}
36+
}
37+
]
38+
},
39+
plugins: [
40+
new CheckerPlugin(),
41+
new TsConfigPathsPlugin({
42+
tsconfig: path.join(__dirname, 'tsconfig.json')
43+
}),
44+
// new webpack.optimize.ModuleConcatenationPlugin(),
45+
new webpack.NoEmitOnErrorsPlugin(),
46+
new webpack.ContextReplacementPlugin(
47+
/angular(\\|\/)core(\\|\/)@angular/,
48+
path.join(__dirname, 'src'), // location of your src
49+
{}
50+
),
51+
new HtmlWebpackPlugin({
52+
template: 'src/app/index.html',
53+
chunksSortMode: 'dependency',
54+
inject: 'body'
55+
}),
56+
],
57+
};
58+
59+
const compiler = (<any>webpack)(CONFIG);
60+
61+
export function build(cb) {
62+
clean();
63+
64+
compiler.run(function(err, stats) {
65+
if (err) {
66+
console.log('Error', err);
67+
}
68+
console.log('[webpack]', stats.toString({
69+
chunks: false,
70+
colors: true
71+
}));
72+
cb();
73+
});
74+
75+
}
76+
77+
watch['description'] = 'Watching build files';
78+
export function watch() {
79+
clean();
80+
81+
compiler.watch({ stdin: true }, function(err, stats) {
82+
if (err) {
83+
console.log('Error', err);
84+
}
85+
console.log('[webpack]', stats.toString({
86+
chunks: false,
87+
colors: true
88+
}));
89+
90+
console.log('[webpack]', 'Gonna sit around and watch for file changes. CTRL^C to kill me');
91+
});
92+
};
93+
94+
export function devServer() {
95+
clean();
96+
97+
const webpackServer = new WebpackDevServer(compiler, {
98+
contentBase: path.join(__dirname, 'dist'),
99+
compress: true,
100+
stats: {
101+
colors: true
102+
},
103+
historyApiFallback: {
104+
rewrites: [
105+
// { from: /^\/$/, to: '/views/landing.html' },
106+
]
107+
},
108+
overlay: {
109+
warnings: true,
110+
errors: true
111+
},
112+
setup: function(app) {
113+
114+
}
115+
});
116+
webpackServer.listen(3000);
117+
118+
}
119+
120+
export function clean() {
121+
shell.rm('-rf', 'dist');
122+
}
123+
124+
export function polyfills() {
125+
126+
}
127+
128+
export default series(
129+
clean,
130+
polyfills,
131+
build
132+
);

0 commit comments

Comments
 (0)