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

Commit ef96adb

Browse files
committed
fixes after using in prod
1 parent 09badce commit ef96adb

8 files changed

+166
-11712
lines changed

Diff for: template/config/webpack.config.base.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
const helpers = require('./helpers'),
2-
NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin'),
3-
CopyWebpackPlugin = require('copy-webpack-plugin');
2+
NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin'),
3+
CopyWebpackPlugin = require('copy-webpack-plugin');
44

55
let config = {
6-
entry: {
7-
'main': helpers.root('/src/main.ts')
8-
},
9-
output: {
10-
path: helpers.root('/dist'),
11-
filename: 'js/[name].[hash].js',
12-
chunkFilename: 'js/[name].[hash].js',
13-
publicPath: '/'
14-
},
15-
devtool: 'source-map',
16-
resolve: {
17-
extensions: ['.ts', '.js', '.html'],
18-
alias: {
19-
'vue$': 'vue/dist/vue.esm.js',
20-
}
21-
},
22-
module: {
23-
rules: [{
24-
test: /\.ts$/,
25-
exclude: /node_modules/,
26-
enforce: 'pre',
27-
loader: 'tslint-loader'
28-
},
29-
{
30-
test: /\.ts$/,
31-
exclude: /node_modules/,
32-
loader: 'awesome-typescript-loader'
33-
},
34-
{
35-
test: /\.html$/,
36-
loader: 'raw-loader',
37-
exclude: ['./src/index.html']
38-
}
39-
],
40-
},
41-
plugins: [
42-
new NamedModulesPlugin(),
43-
new CopyWebpackPlugin([{
44-
from: 'src/assets',
45-
to: './assets'
46-
}, ]),
47-
]
6+
entry: {
7+
'main': helpers.root('/src/main.ts')
8+
},
9+
output: {
10+
path: helpers.root('/dist'),
11+
filename: 'js/[name].[hash].js',
12+
chunkFilename: 'js/[name].[hash].js',
13+
publicPath: '/'
14+
},
15+
devtool: 'source-map',
16+
resolve: {
17+
extensions: ['.ts', '.js', '.html'],
18+
alias: {
19+
'vue$': 'vue/dist/vue.esm.js',
20+
}
21+
},
22+
module: {
23+
rules: [{
24+
test: /\.ts$/,
25+
exclude: /node_modules/,
26+
enforce: 'pre',
27+
loader: 'tslint-loader'
28+
},
29+
{
30+
test: /\.ts$/,
31+
exclude: /node_modules/,
32+
loader: 'awesome-typescript-loader'
33+
},
34+
{
35+
test: /\.html$/,
36+
loader: 'raw-loader',
37+
exclude: ['./src/index.html']
38+
}
39+
],
40+
},
41+
plugins: [
42+
new NamedModulesPlugin(),
43+
new CopyWebpackPlugin([{
44+
from: 'src/assets',
45+
to: './assets'
46+
}])
47+
]
4848
};
4949

5050
module.exports = config;

Diff for: template/config/webpack.config.prod.js

+101-100
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,120 @@
11
const glob = require('glob'),
2-
path = require('path'),
3-
CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'),
4-
UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'),
5-
HtmlWebpackPlugin = require('html-webpack-plugin'),
6-
CompressionPlugin = require('compression-webpack-plugin'),
7-
ExtractTextPlugin = require('extract-text-webpack-plugin'),
8-
PurifyCSSPlugin = require('purifycss-webpack'),
9-
FaviconsWebpackPlugin = require('favicons-webpack-plugin'),
10-
autoprefixer = require('autoprefixer'),
11-
webpackConfig = require('./webpack.config.base'),
12-
helpers = require('./helpers'),
13-
DefinePlugin = require('webpack/lib/DefinePlugin'),
14-
env = require('../environment/prod.env');
2+
path = require('path'),
3+
CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin'),
4+
UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'),
5+
HtmlWebpackPlugin = require('html-webpack-plugin'),
6+
CompressionPlugin = require('compression-webpack-plugin'),
7+
ExtractTextPlugin = require('extract-text-webpack-plugin'),
8+
PurifyCSSPlugin = require('purifycss-webpack'),
9+
FaviconsWebpackPlugin = require('favicons-webpack-plugin'),
10+
autoprefixer = require('autoprefixer'),
11+
webpackConfig = require('./webpack.config.base'),
12+
helpers = require('./helpers'),
13+
DefinePlugin = require('webpack/lib/DefinePlugin'),
14+
env = require('../environment/prod.env');
1515

1616
const extractSass = new ExtractTextPlugin({
17-
filename: 'css/[name].[contenthash].css',
18-
disable: process.env.NODE_ENV === 'development'
17+
filename: 'css/[name].[contenthash].css',
18+
disable: process.env.NODE_ENV === 'development'
1919
});
2020

2121
const purifyCss = new PurifyCSSPlugin({
22-
paths: glob.sync(path.join(__dirname, '../src/**/*.html')),
23-
purifyOptions: {
24-
info: true,
25-
whitelist: []
26-
}
22+
paths: glob.sync(path.join(__dirname, '../src/**/*.html')),
23+
purifyOptions: {
24+
info: true,
25+
whitelist: []
26+
}
2727
});
2828

2929
webpackConfig.module.rules = [...webpackConfig.module.rules,
30-
{
31-
test: /\.scss$/,
32-
use: extractSass.extract({
33-
use: [{
34-
loader: 'css-loader',
35-
options: {
36-
minimize: true,
37-
sourceMap: true,
38-
importLoaders: 2
39-
}
40-
},
41-
{
42-
loader: 'postcss-loader',
43-
options: {
44-
plugins: () => [autoprefixer]
45-
}
46-
},
47-
{
48-
loader: 'sass-loader',
49-
options: {
50-
outputStyle: 'expanded',
51-
sourceMap: true,
52-
sourceMapContents: true
53-
}
54-
}
55-
],
56-
// use style-loader in development
57-
fallback: 'style-loader'
58-
})
59-
},
60-
{
61-
test: /\.(jpg|png|gif)$/,
62-
loader: 'file-loader?name=assets/img/[name].[ext]'
63-
},
64-
{
65-
test: /\.(eot|svg|ttf|woff|woff2)$/,
66-
loader: 'file-loader?name=fonts/[name].[ext]'
67-
}
30+
{
31+
test: /\.scss$/,
32+
use: extractSass.extract({
33+
use: [{
34+
loader: 'css-loader',
35+
options: {
36+
minimize: true,
37+
sourceMap: true,
38+
importLoaders: 2
39+
}
40+
},
41+
{
42+
loader: 'postcss-loader',
43+
options: {
44+
sourceMap: true,
45+
plugins: () => [autoprefixer]
46+
}
47+
},
48+
{
49+
loader: 'sass-loader',
50+
options: {
51+
outputStyle: 'expanded',
52+
sourceMap: true,
53+
sourceMapContents: true
54+
}
55+
}
56+
],
57+
// use style-loader in development
58+
fallback: 'style-loader'
59+
})
60+
},
61+
{
62+
test: /\.(jpg|png|gif)$/,
63+
loader: 'file-loader?name=assets/img/[name].[ext]'
64+
},
65+
{
66+
test: /\.(eot|svg|ttf|woff|woff2)$/,
67+
loader: 'file-loader?name=fonts/[name].[ext]'
68+
}
6869
];
6970

7071
// ensure ts lint fails the build
7172
webpackConfig.module.rules[0].options = {
72-
failOnHint: true
73+
failOnHint: true
7374
};
7475

7576
webpackConfig.plugins = [...webpackConfig.plugins,
76-
new CommonsChunkPlugin({
77-
name: 'vendor',
78-
minChunks: function(module){
79-
return module.context && module.context.indexOf('node_modules') !== -1;
80-
}
81-
}),
82-
new CommonsChunkPlugin({
83-
name: 'manifest',
84-
minChunks: Infinity
85-
}),
86-
extractSass,
87-
purifyCss,
88-
new HtmlWebpackPlugin({
89-
inject: true,
90-
template: helpers.root('/src/index.html'),
91-
favicon: helpers.root('/src/favicon.ico'),
92-
minify: {
93-
removeComments: true,
94-
collapseWhitespace: true,
95-
removeRedundantAttributes: true,
96-
useShortDoctype: true,
97-
removeEmptyAttributes: true,
98-
removeStyleLinkTypeAttributes: true,
99-
keepClosingSlash: true,
100-
minifyJS: true,
101-
minifyCSS: true,
102-
minifyURLs: true
103-
}
104-
}),
105-
new UglifyJsPlugin({
106-
include: /\.js$/,
107-
minimize: true
108-
}),
109-
new CompressionPlugin({
110-
asset: '[path].gz[query]',
111-
test: /\.js$/
112-
}),
113-
new DefinePlugin({
114-
'process.env': env
115-
}),
116-
new FaviconsWebpackPlugin(helpers.root('/src/icon.png'))
77+
new CommonsChunkPlugin({
78+
name: 'vendor',
79+
minChunks: function (module) {
80+
return module.context && module.context.indexOf('node_modules') !== -1;
81+
}
82+
}),
83+
new CommonsChunkPlugin({
84+
name: 'manifest',
85+
minChunks: Infinity
86+
}),
87+
extractSass,
88+
purifyCss,
89+
new HtmlWebpackPlugin({
90+
inject: true,
91+
template: helpers.root('/src/index.html'),
92+
favicon: helpers.root('/src/favicon.ico'),
93+
minify: {
94+
removeComments: true,
95+
collapseWhitespace: true,
96+
removeRedundantAttributes: true,
97+
useShortDoctype: true,
98+
removeEmptyAttributes: true,
99+
removeStyleLinkTypeAttributes: true,
100+
keepClosingSlash: true,
101+
minifyJS: true,
102+
minifyCSS: true,
103+
minifyURLs: true
104+
}
105+
}),
106+
new UglifyJsPlugin({
107+
include: /\.js$/,
108+
minimize: true
109+
}),
110+
new CompressionPlugin({
111+
asset: '[path].gz[query]',
112+
test: /\.js$/
113+
}),
114+
new DefinePlugin({
115+
'process.env': env
116+
}),
117+
new FaviconsWebpackPlugin(helpers.root('/src/icon.png'))
117118
];
118119

119120
module.exports = webpackConfig;

0 commit comments

Comments
 (0)