soraka
Version:
Soraka is a React packaging tool for dcloud.
44 lines (39 loc) • 1.49 kB
JavaScript
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const htmlWebpackPlugin = require('html-webpack-plugin')
const friendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const baseWebpackConfig = require('./webpack.base')
const utils = require('../utils')
const config = require('../config')
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function(name) {
baseWebpackConfig.entry[name] = [path.resolve(config.BIN_PATH, './utils/dev-client')].concat(baseWebpackConfig.entry[name])
})
let defineVars = {}
Object.keys(config.define).map(function(name) {
defineVars[name] = JSON.stringify(config.define[name])
})
module.exports = merge(baseWebpackConfig, {
externals: config.externals,
module: {
noParse: /node_modules\/(jquery|moment|chart\.js)/,
rules: utils.styleLoaders({ sourceMap: true })
},
output: {
path: config.BUILD_PATH,
publicPath: config.PUBLIC_PATH,
filename: './[name].js'
},
// cheap-module-eval-source-map is faster for development
devtool: '#cheap-module-eval-source-map',
plugins: [
new webpack.DefinePlugin(defineVars),
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new htmlWebpackPlugin(config.html),
new friendlyErrorsPlugin()
]
})