html源文件打包,webpack构建怎么打包源文件?

为什么webpack打包只有output了js?

图片、css怎么没output?

webpack.config.js

var path = require('path');

var webpack = require('webpack');

var webpackDevServer = require('webpack-dev-server');

var ExtractTextPlugin = require('extract-text-webpack-plugin');

var autoprefixer = require('autoprefixer');

module.exports = {

entry: {

index: './js/index.js'

},

output: {

path: path.resolve(__dirname, './dist'),

publicPath: '/dist/',

filename: '[name].js'

},

module: {

loaders: [

{

test: /\.css$/,

// loader: 'style-loader!css-loader'

loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader')

},

{

test: /\.scss$/,

loader: 'style!css!sass?sourceMap!postcss'

// loader: ExtractTextPlugin.extract('style-loader', 'css!sass')

},

{

test: /\.js$/,

loader: 'babel',

query: {

presets: ['es2015']

},

exclude: /node_modules/

},

{

test: /\.(png|jpg|gif|svg)$/,

loader: 'file',

options: {

name: '[name].[ext]?[hash]'

}

}

]

},

devServer: {

contentBase: './', // 指定本地服务器所加载的页面目录

colors: true, // 设置为true,使终端输出的文件为彩色

historyApiFallback: true, // 如果设置为true,所有的跳转将指向index.html

inline: true, // 设置为true,当源文件改变时会自动刷新页面

hot: true,

process: true,

port: '8080' // 设置默认监听端口,如果省略,默认为”8080“

},

devtool: '#eval-source-map',

postcss: [

require('autoprefixer')

],

plugins: [

new webpack.HotModuleReplacementPlugin(),

new webpack.optimize.OccurenceOrderPlugin(),

new ExtractTextPlugin('[name].css')

]

}

if (process.env.NODE_ENV === 'production') {

module.exports.devtool = '#source-map'

module.exports.plugins = (module.exports.plugins || []).concat([

new webpack.DefinePlugin({

'process.env': {

NODE_ENV: '"production"'

}

}),

new webpack.optimize.UglifyJsPlugin({

compress: {

warnings: false

}

})

])

}

package.json

"dev": "cross-env NODE_ENV=development webpack-dev-server --open --inline --hot",

"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"

index.js

import '../css/common.scss';

import '../css/index.scss';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值