Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit fd00133

Browse files
committed
Extract CSS/SCSS to app.{platform}.css
Rename app.bundle.{platform}.js => app.{platform}.js
1 parent b76ac18 commit fd00133

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

template/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
"babel-loader": "^7.1.2",
2222
"babel-preset-env": "^1.6.1",
2323
"css-loader": "^0.28.10",
24+
"extract-text-webpack-plugin": "^3.0.2",
2425
"fs-extra": "^5.0.0",
2526
"nativescript-vue-loader": "^0.1.5",
2627
"nativescript-vue-target": "^0.1.0",
2728
"nativescript-vue-template-compiler": "^1.2.0",
29+
"node-sass": "^4.7.2",
30+
"ns-vue-loader": "^0.1.2",
31+
"optimize-css-assets-webpack-plugin": "^3.2.0",
2832
"rimraf": "^2.6.2",
33+
"sass-loader": "^6.0.6",
2934
"vue-template-compiler": "^2.5.13",
3035
"webpack": "^3.11.0",
3136
"winston-color": "^1.0.0"

template/src/App.vue

+7
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
<label text="NativeScript-Vue 🎸"/>
44
</stack-layout>
55
</template>
6+
7+
<style>
8+
Label {
9+
font-size: 24px;
10+
text-align: center;
11+
}
12+
</style>

template/src/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const Vue = require('nativescript-vue');
22
const App = require('./App').default;
33

4+
import './styles.scss';
5+
46
new Vue({
57
template: `<page><app/></page>`,
68

template/src/styles.scss

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$label-color: royalblue;
2+
Label {
3+
color: $label-color;
4+
}

template/template/app/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"android": {
33
"v8Flags": "--expose_gc"
44
},
5-
"main": "app.bundle.js",
5+
"main": "app.js",
66
"name": "{{ name }}",
77
"version": "{{ version }}"
8-
}
8+
}

template/webpack.config.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
const path = require('path');
22
const webpack = require('webpack');
3+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
35
const NativeScriptVueTarget = require('nativescript-vue-target');
46

57
// Generate platform-specific webpack configuration
68
module.exports = platform => {
9+
10+
// CSS / SCSS style extraction loaders
11+
const cssLoader = ExtractTextPlugin.extract({
12+
use: [
13+
{
14+
loader: 'css-loader',
15+
options: {url: false},
16+
},
17+
],
18+
});
19+
const scssLoader = ExtractTextPlugin.extract({
20+
use: [
21+
{
22+
loader: 'css-loader',
23+
options: {url: false},
24+
},
25+
'sass-loader',
26+
],
27+
});
28+
729
return {
830
target: NativeScriptVueTarget,
931
entry: path.resolve(__dirname, './src/main.js'),
1032
output: {
1133
path: path.resolve(__dirname, './dist/app'),
12-
filename: `app.bundle.${platform}.js`,
34+
filename: `app.${platform}.js`,
1335
},
1436
module: {
1537
rules: [
@@ -18,9 +40,23 @@ module.exports = platform => {
1840
exclude: /(node_modules)/,
1941
loader: 'babel-loader',
2042
},
43+
{
44+
test: /\.css$/,
45+
use: cssLoader,
46+
},
47+
{
48+
test: /\.scss$/,
49+
use: scssLoader,
50+
},
2151
{
2252
test: /\.vue$/,
23-
loader: 'nativescript-vue-loader',
53+
loader: 'ns-vue-loader',
54+
options: {
55+
loaders: {
56+
css: cssLoader,
57+
scss: scssLoader,
58+
},
59+
},
2460
},
2561
],
2662
},
@@ -43,6 +79,12 @@ module.exports = platform => {
4379
callback();
4480
},
4581
plugins: [
82+
new ExtractTextPlugin({filename: `app.${platform}.css`}),
83+
new OptimizeCssAssetsPlugin({
84+
cssProcessor: require('cssnano'),
85+
cssProcessorOptions: {discardComments: {removeAll: true}},
86+
canPrint: false,
87+
}),
4688
new webpack.optimize.UglifyJsPlugin({
4789
compress: {warnings: false},
4890
output: {comments: false},

0 commit comments

Comments
 (0)