[Improvement] upgrade to webpack 4 (#693)

This commit is contained in:
neverland
2018-03-15 10:13:48 +08:00
committed by GitHub
parent 461b6732eb
commit f13a0779fd
18 changed files with 6384 additions and 4220 deletions
+11 -8
View File
@@ -1,16 +1,20 @@
const path = require('path');
const webpack = require('webpack');
const config = require('./webpack.config.dev.js');
const isMinify = process.argv.indexOf('-p') !== -1;
module.exports = Object.assign({}, config, {
mode: 'production',
entry: {
'vant': './packages/index.js'
},
output: {
filename: isMinify ? './lib/[name].min.js' : './lib/[name].js',
path: path.join(__dirname, '../lib'),
library: 'vant',
libraryTarget: 'umd',
umdNamedDefine: true
filename: isMinify ? '[name].min.js' : '[name].js',
umdNamedDefine: true,
globalObject: 'this'
},
externals: {
vue: {
@@ -20,10 +24,9 @@ module.exports = Object.assign({}, config, {
amd: 'vue'
}
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.ModuleConcatenationPlugin()
]
plugins: [],
performance: false,
optimization: {
minimize: isMinify
}
});
+5 -26
View File
@@ -3,16 +3,10 @@ const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const cache = {
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve(__dirname, '../node_modules/.cache-loader')
}
};
module.exports = {
mode: 'development',
entry: {
'vant-docs': './docs/src/index.js',
'vant-mobile': './docs/src/mobile.js'
@@ -20,7 +14,6 @@ module.exports = {
output: {
path: path.join(__dirname, '../docs/dist'),
publicPath: '/',
filename: '[name].js',
chunkFilename: 'async_[name].js'
},
devServer: {
@@ -34,21 +27,17 @@ module.exports = {
stats: 'errors-only'
},
resolve: {
modules: [path.join(__dirname, '../node_modules'), 'node_modules'],
extensions: ['.js', '.vue', '.css'],
alias: {
vue: 'vue/dist/vue.runtime.esm.js',
packages: path.join(__dirname, '../packages'),
lib: path.join(__dirname, '../lib'),
components: path.join(__dirname, '../docs/src/components')
packages: path.join(__dirname, '../packages')
}
},
module: {
loaders: [
rules: [
{
test: /\.vue$/,
use: [
cache,
{
loader: 'vue-loader',
options: {
@@ -61,10 +50,7 @@ module.exports = {
{
test: /\.js$/,
exclude: /node_modules|vue-router\/|vue-loader\//,
use: [
cache,
'babel-loader'
]
use: 'babel-loader'
},
{
test: /\.css$/,
@@ -78,7 +64,6 @@ module.exports = {
{
test: /\.md/,
use: [
cache,
'vue-loader',
'fast-vue-md-loader'
]
@@ -103,15 +88,9 @@ module.exports = {
filename: 'examples.html',
inject: true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: 2,
filename: isProduction ? 'vendor.[hash:8].js' : 'vendor.js'
}),
new ExtractTextPlugin({
filename: isProduction ? '[name].[hash:8].css' : '[name].css',
allChunks: true
}),
new FriendlyErrorsPlugin()
})
]
};
+2 -9
View File
@@ -4,19 +4,12 @@ const path = require('path');
const devConfig = require('./webpack.config.dev.js');
module.exports = merge(devConfig, {
mode: 'production',
output: {
path: path.join(__dirname, '../docs/dist'),
publicPath: 'https://img.yzcdn.cn/zanui/vant/',
filename: '[name].[hash:8].js',
umdNamedDefine: true,
chunkFilename: 'async_[name].[chunkhash:8].js'
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new webpack.optimize.UglifyJsPlugin()
]
}
});