-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
172 lines (147 loc) · 4.04 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const path = require('path');
const webpack = require('webpack');
const winston = require('winston-color');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const WebpackSynchronizableShellPlugin = require('webpack-synchronizable-shell-plugin');
const NativeScriptVueExternals = require('nativescript-vue-externals');
const NativeScriptVueTarget = require('nativescript-vue-target');
// Prepare NativeScript application from template (if necessary)
require('./prepare')();
// Generate platform-specific webpack configuration
const config = (platform, launchArgs) => {
winston.info(`Bundling application for ${platform}...`);
// CSS / SCSS style extraction loaders
const cssLoader = ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {url: false},
},
],
});
const scssLoader = ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
url: false,
includePaths: [path.resolve(__dirname, 'node_modules')],
},
},
'sass-loader',
],
});
return {
target: NativeScriptVueTarget,
entry: path.resolve(__dirname, './src/main.ts'),
output: {
path: path.resolve(__dirname, './dist/app'),
filename: `app.${platform}.js`,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
},
{
test: /\.ts$/,
exclude: /(node_modules)/,
loader: 'ts-loader',
options: { appendTsSuffixTo: [/\.vue$/] }
},
{
test: /\.css$/,
use: cssLoader,
},
{
test: /\.scss$/,
use: scssLoader,
},
{
test: /\.vue$/,
loader: 'ns-vue-loader',
options: {
loaders: {
css: cssLoader,
scss: scssLoader,
ts: 'ts-loader'
},
esModule: true
},
},
],
},
resolve: {
alias: { 'vue$': 'nativescript-vue' },
modules: [
'node_modules/tns-core-modules',
'node_modules',
],
extensions: [
`.${platform}.css`,
'.css',
`.${platform}.scss`,
'.scss',
`.${platform}.js`,
'.js',
`.${platform}.ts`,
'.ts',
`.${platform}.vue`,
'.vue',
],
},
externals: NativeScriptVueExternals,
plugins: [
// Extract CSS to separate file
new ExtractTextPlugin({filename: `app.${platform}.css`}),
// Optimize CSS output
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorOptions: {
discardComments: { removeAll: true },
normalizeUrl: false
},
canPrint: false,
}),
// Minify JavaScript code
new webpack.optimize.UglifyJsPlugin({
compress: {warnings: false},
output: {comments: false},
}),
// Copy src/assets/**/* to dist/
new CopyWebpackPlugin([
{from: 'assets', context: 'src'},
]),
// Execute post-build scripts with specific arguments
new WebpackSynchronizableShellPlugin({
onBuildEnd: {
scripts: [
... launchArgs ? [`node launch.js ${launchArgs}`] : [],
],
blocking: false,
},
}),
],
stats: 'errors-only',
node: {
'http': false,
'timers': false,
'setImmediate': false,
'fs': 'empty',
},
};
};
// Determine platform(s) and action from webpack env arguments
module.exports = env => {
const action = (!env || !env.tnsAction) ? 'build' : env.tnsAction;
if (!env || (!env.android && !env.ios)) {
return [config('android'), config('ios', action)];
}
return env.android && config('android', `${action} android`)
|| env.ios && config('ios', `${action} ios`)
|| {};
};