soraka
Version:
Soraka is a React packaging tool for dcloud.
86 lines (82 loc) • 2.74 kB
JavaScript
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base')
const htmlWebpackPlugin = require('html-webpack-plugin')
const copyWebpackPlugin = require('copy-webpack-plugin')
const extractTextPlugin = require('extract-text-webpack-plugin')
const optimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const utils = require('../utils')
const config = require('../config')
let defineVars = {}
Object.keys(config.define).map(function(name) {
defineVars[name] = JSON.stringify(config.define[name])
})
module.exports = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: false,
extract: true
})
},
devtool: false,
output: {
path: config.BUILD_PATH,
publicPath: config.PUBLIC_PATH,
filename: path.join(config.ASSETS_PATH, './js/[name].[chunkhash:5].js'),
chunkFilename: path.join(config.ASSETS_PATH, './js/[id].[chunkhash:5].js')
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin(defineVars),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
sourceMap: true
}),
// extract css into its own file
new extractTextPlugin({
filename: 'assets/css/[name].[contenthash:5].css'
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
new optimizeCSSPlugin({
cssProcessorOptions: {
safe: true
}
}),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new htmlWebpackPlugin(config.html),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module, count) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ['vendor']
}),
// copy custom static assets
new copyWebpackPlugin([
{
from: config.SOURCE_ASSETS_PATH,
to: config.BUILD_ASSETS_PATH,
ignore: ['.*']
}
])
]
})