You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3 KiB

5 years ago
const path = require('path');
5 years ago
const autoprefixer = require('autoprefixer');
const TerserPlugin = require('terser-webpack-plugin');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
// const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// still not work...
// const imgOutputPath = process.env.ENV_MODE === "build" ? 'images/[name].[ext]' : '../images/[name].[ext]';
5 years ago
module.exports = [{
mode: "development", // "production" | "development" | "none"
entry: {
main: ['./src/ts/index.ts', './src/scss/index.scss']
5 years ago
},
output: {
path: path.resolve(__dirname, './dist'),
filename: './js/bundle.js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: path.join(__dirname, './dist'), //编译打包文件的位置
publicPath: '/',
port: 8080, //服务器端口号
host: '0.0.0.0',
// proxy: {}, //代理列表
compress: true,
// historyApiFallback: true, //开启服务器history重定向模式
5 years ago
},
module: {
rules: [{
test: /\.(png|jpg|gif|svg)$/,
exclude: [
path.resolve(__dirname, './node_modules'),
],
use: {
loader: 'file-loader',
options: {
// name(file) {
// return './images/[name].[ext]';
// },
name: '../images/[name].[ext]'
// outputPath: './images',
},
},
},
{
5 years ago
test: /\.scss$/,
use: [
//MiniCssExtractPlugin.loader,
{
5 years ago
loader: 'file-loader',
options: {
name: './css/bundle.css',
// outputPath: './css',
5 years ago
},
},
{
loader: 'extract-loader'
},
{
loader: 'css-loader'
},
5 years ago
{
loader: 'postcss-loader',
options: {
plugins: () => [autoprefixer()]
5 years ago
}
},
{
loader: 'sass-loader',
5 years ago
options: {
sourceMap: true,
sassOptions: {
includePaths: ['./node_modules']
},
}
5 years ago
},
5 years ago
]
},
{
test: /\.tsx?$/,
use: [{
loader: 'babel-loader',
query: {
presets: ['@babel/preset-typescript'],
5 years ago
},
}, ],
5 years ago
exclude: /node_modules/
},
5 years ago
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
// optimization: {
// minimize: true,
// minimizer: [new TerserPlugin({
// sourceMap: false,
// })],
// },
plugins: [
new CopyPlugin([
// { from: './src/images', to: './images' },
{
from: './src/*.html',
to: './[name].[ext]',
toType: 'template',
},
]),
// new HtmlWebpackPlugin({
// filename: 'index.html',
// template: './src/index.html',
// chunks: ['index']
// }),
// new HtmlWebpackPlugin({
// filename: 'single.html',
// template: './src/single.html',
// chunks: ['single']
// })
// new MiniCssExtractPlugin({
// // Options similar to the same options in webpackOptions.output
// // both options are optional
// filename: "[name].css",
// chunkFilename: "[name]_[hash].css"
// })
]
5 years ago
}];