Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Commit d093384

Browse files
committed
shrink module config & export router for module
1 parent 673117b commit d093384

File tree

5 files changed

+28
-129
lines changed

5 files changed

+28
-129
lines changed
+3-83
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
const glob = require('glob'),
2-
path = require('path'),
3-
CompressionPlugin = require('compression-webpack-plugin'),
4-
ExtractTextPlugin = require('extract-text-webpack-plugin'),
5-
PurifyCSSPlugin = require('purifycss-webpack'),
6-
autoprefixer = require('autoprefixer'),
7-
webpackConfig = require('./webpack.config.base'),
8-
helpers = require('./helpers'),
9-
DefinePlugin = require('webpack/lib/DefinePlugin'),
10-
env = require('../environment/prod.env');
11-
12-
const extractSass = new ExtractTextPlugin({
13-
filename: 'css/[name].[contenthash].css',
14-
disable: process.env.NODE_ENV === 'development'
15-
});
16-
17-
const purifyCss = new PurifyCSSPlugin({
18-
paths: glob.sync(path.join(__dirname, '../src/**/*.html')),
19-
purifyOptions: {
20-
info: true,
21-
whitelist: []
22-
}
23-
});
24-
25-
webpackConfig.entry.main = helpers.root('/src/module.ts');
1+
const
2+
webpackConfig = require('./webpack.config.prod'),
3+
helpers = require('./helpers');
264

275
webpackConfig.output = {
286
path: helpers.root('/dist'),
@@ -40,62 +18,4 @@ webpackConfig.externals = {
4018
'vue-router': 'vue-router'
4119
};
4220

43-
webpackConfig.module.rules = [...webpackConfig.module.rules,
44-
{
45-
test: /\.scss$/,
46-
use: extractSass.extract({
47-
use: [{
48-
loader: 'css-loader',
49-
options: {
50-
minimize: true,
51-
sourceMap: true,
52-
importLoaders: 2
53-
}
54-
},
55-
{
56-
loader: 'postcss-loader',
57-
options: {
58-
plugins: () => [autoprefixer]
59-
}
60-
},
61-
{
62-
loader: 'sass-loader',
63-
options: {
64-
outputStyle: 'expanded',
65-
sourceMap: true,
66-
sourceMapContents: true
67-
}
68-
}
69-
],
70-
// use style-loader in development
71-
fallback: 'style-loader'
72-
})
73-
},
74-
{
75-
test: /\.(jpg|png|gif)$/,
76-
loader: 'file-loader?name=assets/img/[name].[ext]'
77-
},
78-
{
79-
test: /\.(eot|svg|ttf|woff|woff2)$/,
80-
loader: 'file-loader?name=fonts/[name].[ext]'
81-
}
82-
];
83-
84-
// ensure ts lint fails the build
85-
webpackConfig.module.rules[0].options = {
86-
failOnHint: true
87-
};
88-
89-
webpackConfig.plugins = [...webpackConfig.plugins,
90-
extractSass,
91-
purifyCss,
92-
new CompressionPlugin({
93-
asset: '[path].gz[query]',
94-
test: /\.min\.js$/
95-
}),
96-
new DefinePlugin({
97-
'process.env': env
98-
})
99-
];
100-
10121
module.exports = webpackConfig;

template/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"npm": ">=3"
1212
},
1313
"scripts": {
14-
"build": "cross-env NODE_ENV=production npm run clean && npm run test && npm run compile",
15-
"module": "cross-env NODE_ENV=production npm run clean && npm run test && npm run compile:module",
14+
"prebuild:production": "cross-env NODE_ENV=production npm run clean && npm run test",
15+
"build": "npm run prebuild:production && npm run compile",
16+
"module": "npm run prebuild:production && npm run compile:module",
1617
"build:parts": "npm run sass && npm run compile",
1718
"ci:teamcity": "karma --env=tc start karma.coverage.js && npm run coverage:remap",
1819
"ci:jenkins": "karma --env=jk start karma.coverage.js && npm run coverage:remap",
1920
"clean": "rimraf dist && rimraf coverage",
2021
"compile": "webpack --config config/webpack.config.prod.js",
2122
"compile:module": "webpack --config config/webpack.config.module.js",
2223
"prepublishOnly": "npm run module",
23-
"node-module": "webpack --config config/webpack.config.module.js",
2424
"coverage": "npm run coverage:run && npm run coverage:remap && npm run coverage:open",
2525
"coverage:open": "opn coverage/html-ts/index.html",
2626
"coverage:remap": "remap-istanbul -i coverage/json/coverage-final.json -o coverage/html-ts -t html",

template/src/main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Vue from 'vue';
2-
import VueRouter from 'vue-router';
32
import { makeHot, reload } from './util/hot-reload';
43
import { createRouter } from './router';
54

@@ -13,7 +12,7 @@ if (process.env.ENV === 'development' && module.hot) {
1312
// first arguments for `module.hot.accept` and `require` methods have to be static strings
1413
// see https://github.com/webpack/webpack/issues/5668
1514
makeHot(navbarModuleId, navbarComponent,
16-
module.hot.accept('./components/navbar', () => reload(navbarModuleId, (<any>require('./components/navbar')).NavbarComponent)));
15+
module.hot.accept(navbarModuleId, () => reload(navbarModuleId, (<any>require(navbarModuleId)).NavbarComponent)));
1716
}
1817

1918
new Vue({

template/src/module.ts

-23
This file was deleted.

template/src/router.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,33 @@ if (process.env.ENV === 'development' && module.hot) {
1717
// first arguments for `module.hot.accept` and `require` methods have to be static strings
1818
// see https://github.com/webpack/webpack/issues/5668
1919
makeHot(homeModuleId, homeComponent,
20-
module.hot.accept('./components/home', () => reload(homeModuleId, (<any>require('./components/home')).HomeComponent)));
20+
module.hot.accept(homeModuleId, () => reload(homeModuleId, (<any>require(homeModuleId)).HomeComponent)));
2121

2222
makeHot(aboutModuleId, aboutComponent,
23-
module.hot.accept('./components/about', () => reload(aboutModuleId, (<any>require('./components/about')).AboutComponent)));
23+
module.hot.accept(aboutModuleId, () => reload(aboutModuleId, (<any>require(aboutModuleId)).AboutComponent)));
2424

2525
makeHot(listModuleId, listComponent,
26-
module.hot.accept('./components/list', () => reload(listModuleId, (<any>require('./components/list')).ListComponent)));
26+
module.hot.accept(listModuleId, () => reload(listModuleId, (<any>require(listModuleId)).ListComponent)));
2727
}
2828

29-
Vue.use(VueRouter);
30-
31-
export const createRoutes: () => RouteConfig[] = () => [
32-
{
33-
path: '/',
29+
export function createRoutes(prefix: string = ''): RouteConfig[] {
30+
return [{
31+
path: prefix + '/',
3432
component: homeComponent,
3533
},
36-
{
37-
path: '/about',
38-
component: aboutComponent,
39-
},
40-
{
41-
path: '/list',
42-
component: listComponent,
43-
}
44-
];
34+
{
35+
path: prefix + '/about',
36+
component: aboutComponent,
37+
},
38+
{
39+
path: prefix + '/list',
40+
component: listComponent,
41+
}
42+
];
43+
}
44+
4545

46-
export const createRouter = () => new VueRouter({ mode: 'history', routes: createRoutes() });
46+
export const createRouter = () => {
47+
Vue.use(VueRouter);
48+
return new VueRouter({ mode: 'history', routes: createRoutes() });
49+
};

0 commit comments

Comments
 (0)