123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- const webpack = require('webpack')
- const path = require('path')
- const HtmlWebpackPlugin = require('html-webpack-plugin') //html插件
- const ExtractTextPlugin = require("extract-text-webpack-plugin")//文本插件
- const readEntryFile = require('./webpack.common.js')
- const autoprefixer = require('autoprefixer')
- const postcssSprites = require('postcss-sprites')
- const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
- const svnpath = '../../../pub' || 'D://fed/pub'//支持相对和绝对地址
- const version = ''
- const filepath = '/zt2018/tankehezih5/'
- const staticPath = /:\/\//.test(svnpath) ? path.joiwn(svnpath, filepath, version) : path.join(__dirname, svnpath, filepath, version)//根据相对还是绝对地址拼接成绝对地址
- const cdn = ['//pub.dwstatic.com', filepath, version].join('')
- /**
- * 默认入口是有vendor的 如果不需要可以去除
- */
- var entry = {
- }
- var plugins = [
- new webpack.optimize.CommonsChunkPlugin('vendor'),
- new webpack.optimize.UglifyJsPlugin(),
- new webpack.ProvidePlugin({
- _: "underscore"
- }),
- new webpack.DefinePlugin({
- 'process.env': {
- 'NODE_ENV': JSON.stringify('production')
- }
- }),
- new ExtractTextPlugin({
- filename: "css/[name].css",
- allChunks: true
- }),
- ]
- readEntryFile().forEach(function (file) {
- plugins.push(new HtmlWebpackPlugin({
- filename: file.name + '.html',
- template: file.htmlentry,
- inject: 'body',
- chunksSortMode: 'manual',
- chunks: ['vendor', file.name]
- }))
- entry[file.name] = file.jsentry
- }, this);
- module.exports = {
- entry: entry,
- output: {
- publicPath: '/',
- filename: 'js/[name].js',
- path: path.resolve(staticPath, '')
- },
- module: {
- rules: [
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- exclude: /node_modules/
- },
- {
- test: /\.js$/,
- use: [{
- loader: 'babel-loader'
- }],
- exclude: /node_modules/,
- },
- {
- test: /\.css$/,
- use: ExtractTextPlugin.extract({
- fallback: "style-loader",
- use: "css-loader",
- publicPath: path.resolve(cdn, './css')
- })
- },
- {
- test: /\.scss$/, use: ExtractTextPlugin.extract({
- fallback: 'style-loader',
- use: [{
- loader: "css-loader",
- }, {
- loader: "postcss-loader",
- options: {
- ident: 'postcss',
- plugins: () => [
- autoprefixer({
- browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 8', 'iOS >= 8', 'Android >= 4'],
- }),
- postcssSprites({
- stylesheetPath: './src/img',
- spritePath: path.resolve(staticPath, './img/sprite'),
- filterBy: [
- function (image) {
- if (image.originalUrl.indexOf('?__sprite') === -1) {
- return Promise.reject()
- }
- return Promise.resolve()
- }
- ]
- })
- ],
- },
- }, {
- loader: "sass-loader"
- }]
- })
- },
- {
- test: /\.html$/,
- use: [{
- loader: 'html-loader',
- options: {
- attrs: ['img:src', 'img:data-src'],
- minimize: false
- }
- }]
- },
- {
- test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
- loader: 'file-loader',
- options: {
- useRelativePath: true,
- name(file) {
- if (file.indexOf('sprite') === -1)
- return '[name].[ext]'
- else
- return 'sprite/[name].[ext]'
- },
- }
- },
- {
- test: /\.tmpl$/,
- use: 'raw-loader'
- }
- ]
- },
- // devtool: 'source-map',
- plugins: plugins,
- resolve: {
- alias: {
- 'vue$': 'vue/dist/vue.esm.js',
- "jsonp": path.resolve(__dirname, './src/lib/jsonp.js'),
- "lib": path.resolve(__dirname, './src/lib/library.js')
- }
- }
- }
|