1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- const path = require('path');
- const htmlPlugin= require('html-webpack-plugin');
- const PurifyCSSPlugin = require("purifycss-webpack");
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
- const glob = require('glob');
- var website ={
- publicPath:"http://localhost:1717/"
- }
- module.exports={
- //入口文件的配置项
- entry:{
- entry:'./src/index.js',
- editor: './src/js/yzWebeditor'
- },
- //出口文件的配置项
- output:{
- //打包的路径文职
- path:path.resolve(__dirname,'dist'),
- //打包的文件名称
- filename:'[name]-bundle.js',
- publicPath:website.publicPath
- },
- node: {
- fs: "empty"
- },
- //模块:例如解读CSS,图片如何转换,压缩
- module:{
- rules: [
- {
- test: /\.css/,
- exclude:/node_modules/,
- use: ["style-loader","css-loader", "postcss-loader"],
- },{
- test: /\.less$/,
- use: [
- 'style-loader',
- { loader: 'css-loader', options: { importLoaders: 1 } },
- 'postcss-loader',
- 'less-loader'
- ]
- },{
- test:/\.(png|jpg|gif)/ ,
- use:[{
- loader:'url-loader',
- options:{
- limit:5000,
- outputPath:'images/',
- }
- }]
- },{
- test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
- loader: 'url-loader',
- options: {
- limit: 10000
- }
- },{
- test: /\.(htm|html)$/i,
- use:[ 'html-withimg-loader']
- },{
- test:/\.(jsx|js)$/,
- use:{
- loader:'babel-loader'
- },
- exclude:/node_modules/
- }
- ]
- },
- //插件,用于生产模版和各项功能
- plugins:[
- new htmlPlugin({
- minify:{
- removeAttributeQuotes:true
- },
- hash:true,
- template:'./src/index.html'
- }),
- new UglifyJsPlugin({
- uglifyOptions: {
- ie8: true
- }
- }),
- new PurifyCSSPlugin({
- // Give paths to parse for rules. These should be absolute!
- paths: glob.sync(path.join(__dirname, 'src/*.html')),
- })
- ],
- //配置webpack开发服务功能
- devServer:{
- //设置基本目录结构
- contentBase:path.resolve(__dirname,'dist'),
- //服务器的IP地址,可以使用IP也可以使用localhost
- host:'localhost',
- //服务端压缩是否开启
- compress:true,
- //配置服务端口号
- port:1717
- }
- }
|