Skip to content

Instantly share code, notes, and snippets.

@legend80s
Last active October 12, 2016 11:17
Show Gist options
  • Save legend80s/b92bcac3a64d9a7c2ce70b8bc1f15277 to your computer and use it in GitHub Desktop.
Save legend80s/b92bcac3a64d9a7c2ce70b8bc1f15277 to your computer and use it in GitHub Desktop.
Webpack config
/**
* npm install webpack css-loader extract-text-webpack-plugin file-loader html-loader style-loader html-webpack-plugin -S -E
*
* build
└── app.js
build
├── bundle.css
├── bundle.js
└── fonts
├── glyphicons-halflings-regular.eot
├── glyphicons-halflings-regular.svg
├── glyphicons-halflings-regular.ttf
└── glyphicons-halflings-regular.woff
*/
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const appRoot = path.join(__dirname, './src');
module.exports = {
entry: {
app: ['./src/app.js'],
},
output: {
path: path.resolve(__dirname, './build'),
filename: 'bundle.js',
},
resolve: {
root: [appRoot],
extensions: ['', '.js'],
},
plugins: [
new ExtractTextPlugin('bundle.css'),
new HtmlWebpackPlugin({
filename: './index.html', // 生成的入口页地址相对于 build 目录
template: './src/index.html', // 模板文件相对于当前执行脚本
}),
],
module: {
noParse: [/sdk\.bundle\.js/],
loaders: [
{ test: /\.html$/, loader: 'html' },
{ test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
{ test: /\.ttf\b|\.woff\b|\.woff2$|\.eot\b|\.svg\b/, loader: 'file?name=fonts/[name].[ext]' },
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment