123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- const webpack = require('webpack')
- const path = require('path')
- const readEntryFile = require('./webpack.common.js')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const ExtractTextPlugin = require("extract-text-webpack-plugin")
- const CleanWebpackPlugin = require('clean-webpack-plugin')
- var entry = {
- vendor: ['jquery']
- }
- var plugins = [
- new webpack.HotModuleReplacementPlugin(),
- new CleanWebpackPlugin(['dist']),
- new webpack.optimize.CommonsChunkPlugin('vendor'),
- new webpack.ProvidePlugin({
- $: "jquery",
- jQuery: "jquery",
- "window.jQuery": "jquery",
- _: "underscore"
- })
- ]
- 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: '[name].js',
- path: path.resolve(__dirname, 'dist')
- },
- module: {
- rules: [
- {
- test: /\.js$/,
- loader: 'babel-loader',
- exclude: /node_modules/
- },
- {
- test: /\.css$/,
- use: [{
- loader: "style-loader",
- }, {
- loader: "css-loader",
- options: {
- sourceMap: true
- }
- }]
- },
- {
- test: /\.scss$/,
- use: [{
- loader: "style-loader",
- }, {
- loader: "css-loader",
- options: {
- sourceMap: true
- }
- }, {
- loader: "postcss-loader",
- options: {
- ctx: {
- autoprefixer: true
- }, sourceMap: true
- }
- }, {
- loader: "sass-loader",
- options: {
- sourceMap: true
- }
- }]
- },
- {
- test: require.resolve('jquery'),
- use: [{
- loader: 'expose-loader',
- options: 'jQuery'
- }, {
- loader: 'expose-loader',
- options: '$'
- }]
- },
- {
- 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: {
- name: '[name]_[hash:6].[ext]',
- }
- },
- {
- test: /\.tmpl$/,
- use: 'ejs-loader'
- }
- ]
- },
- devtool: 'inline-source-map',
- devServer: {
- contentBase: './dist',
- host: '127.0.0.1',
- hot: true,
- disableHostCheck: true
- },
- plugins: plugins,
- resolve: {
- }
- }
|