bm_scaffold_async_router
Version:
本木前端脚手架-异步路由版
111 lines (103 loc) • 3.71 kB
JavaScript
/**
* @Author: songqi
* @Date: 2017-01-13
* @Last modified by: songqi
* @Last modified time: 2017-03-23
*/
var path = require('path'),
webpack = require('webpack'),
argv = require('yargs').argv,
readConfig = require('../../../utils/readConfig'),
getFiles = require('../../../utils/getWebpackFiles')
var include = path.join(process.cwd(), 'src/js/'),
exclude = [
path.join(process.cwd(), '/src/js/base_libs'),
path.join(process.cwd(), '/src/js/baseLibs')
];
process.noDeprecation = true;
var webpackConfig = {
entry: getFiles.getEntry(),
output: {
path: path.join(process.cwd(), 'dist'),
publicPath: path.join(process.cwd(), 'dist/js/'),
filename: '[name].js',
chunkFilename: '[chunkhash].js'
},
module: {
rules: [{
test: /\.vue$/,
include,
exclude,
loader: 'weex-loader',
options: {
stylus: 'vue-style-loader!css-loader!stylus-loader',
styl: 'vue-style-loader!css-loader!stylus-loader'
}
}, {
test: /\.(jsx?|babel|es6)$/,
include,
exclude,
loader: 'babel-loader',
options: {
plugins: [
require('babel-plugin-transform-runtime'),
require('babel-plugin-transform-async-to-generator')
],
presets: [
require('babel-preset-es2015'),
require('babel-preset-stage-0')
]
}
}]
},
resolveLoader: {
modules: [path.resolve(__dirname, '../../../', 'node_modules')]
},
plugins: [
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.BannerPlugin({
banner: '// { "framework": "Vue" }\n',
raw: true
})
],
resolve: {
modules: [
path.resolve(process.cwd(), 'node_modules')
],
extensions: ['.js', '.vue', '.json', '.coffee', '.css', '.less', '.sass'],
alias: getFiles.getAlias()
}
};
var definePlugin;
// 根据环境配置参数
var isWeex = readConfig.get('weex'),
isCommonServer = argv._[0] === 'server',
isCommonMin = argv._[0] === 'min',
isCommonMinWeex = argv._[0] === 'minWeex',
isErosDev = argv._[0] === 'eros' && argv._[1] === 'dev',
isErosBuild = argv._[0] === 'eros' && argv._[1] === 'build',
isErosPack = argv._[0] === 'eros' && argv._[1] === 'pack';
if (isWeex && (isCommonServer || isErosDev) ){
definePlugin = new webpack.DefinePlugin(Object.assign({
'process.env': {
NODE_ENV: JSON.stringify('development')
}
}, readConfig.get('webpackDevEnv') || []))
webpackConfig.devtool = readConfig.get('webpackDevtool') || 'eval';
webpackConfig.plugins = webpackConfig.plugins.concat([definePlugin], readConfig.get('webpackDevPlugins') || []);
} else if (isWeex && (isCommonMin || isCommonMinWeex || isErosBuild || isErosPack)) {
definePlugin = new webpack.DefinePlugin(Object.assign({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}, readConfig.get('webpackProdEnv') || []));
webpackConfig.devtool = readConfig.get('webpackProdtool') || 'cheap-module-source-map';
webpackConfig.plugins = webpackConfig.plugins.concat([definePlugin], readConfig.get('webpackProdPlugins') || []);
}
if (isWeex) {
module.exports = webpack(webpackConfig)
} else {
module.exports = false
}