Last active
April 11, 2019 10:39
-
-
Save simonkuang/25e8d8d41e9d49353c2d6e68707f56ab to your computer and use it in GitHub Desktop.
a whole new webpack env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "qiuzhi-chrome-extension", | |
"version": "1.0.0", | |
"main": "webpack.config.js", | |
"private": true, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"watch": "webpack --watch", | |
"start": "webpack-dev-server --open", | |
"build": "webpack" | |
}, | |
"license": "MIT", | |
"devDependencies": { | |
"copy-webpack-plugin": "*", | |
"css-loader": "*", | |
"file-loader": "*", | |
"html-webpack-plugin": "*", | |
"mini-css-extract-plugin": "*", | |
"node-sass": "*", | |
"sass-loader": "*", | |
"style-loader": "*", | |
"ts-loader": "*", | |
"webpack": "^4.29.6", | |
"webpack-cli": "^3.3.0", | |
"webpack-dev-server": "^3.3.1" | |
}, | |
"dependencies": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
entry: { | |
show: './src/show.js', | |
background: './src/background.js' | |
}, | |
devtool: 'inline-source-map', | |
devServer: { | |
contentBase: './dist', | |
compress: false, | |
port: 8080 | |
}, | |
resolve: { | |
extensions: [ | |
'.tsx', '.ts', '.js', | |
'.scss', '.sass' | |
] | |
}, | |
output: { | |
filename: '[name].bundle.js', | |
path: path.resolve(__dirname, 'dist') | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.tsx?$/, | |
use: 'ts-loader', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.(png|svg|jpg|jpeg|gif)$/, | |
use: 'file-loader' | |
}, | |
{ | |
test: /\.(woff|woff2|eot|ttf|otf)$/, | |
use: 'file-loader' | |
}, | |
{ | |
test: /\.(scss|sass)$/, | |
use: [ | |
process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader, | |
{loader: "css-loader"}, | |
{loader: "sass-loader"} | |
] | |
} | |
] | |
}, | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
template: './src/index.html', | |
filename: 'index.html', | |
minify: { | |
collapseWhitespace: true, | |
}, | |
hash: true, | |
}), | |
new CopyWebpackPlugin([ | |
{from: path.join(__dirname, 'src/index.html'), to: path.join(__dirname, 'dist/')}, // for demo | |
{from: path.join(__dirname, 'src/popup.html'), to: path.join(__dirname, 'dist/')}, | |
{from: path.join(__dirname, 'src/manifest.json'), to: path.join(__dirname, 'dist/')}, | |
{from: path.join(__dirname, 'src/images/'), to: path.join(__dirname, 'dist/')}, | |
]), | |
new MiniCssExtractPlugin({ | |
filename: "[name].css", | |
chunkFilename: "[id].css" | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment