Skip to content

Instantly share code, notes, and snippets.

@kb10uy
Last active September 4, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kb10uy/c54a9f531fd80937e6716ac0a17a6d1c to your computer and use it in GitHub Desktop.
Save kb10uy/c54a9f531fd80937e6716ac0a17a6d1c to your computer and use it in GitHub Desktop.
2018/09 オレオレウェッパコ
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackManifestPlugin = require('webpack-manifest-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const AutoPrefixer = require('autoprefixer');
const publicDirectory = path.resolve(__dirname, 'dist/public');
module.exports = {
entry: {
script: './assets/scripts/main.ts',
style: './assets/styles/main.scss',
},
output: {
path: publicDirectory,
filename: '[hash].js',
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
options: {
plugins: [AutoPrefixer()],
},
},
'sass-loader',
],
},
],
},
plugins: [
new CleanWebpackPlugin(['./dist/public/*.js', './dist/public/*.css'], {
beforeEmit: true,
watch: true,
}),
new MiniCssExtractPlugin({
filename: '[hash].css',
}),
new CopyWebpackPlugin([
{
from: './assets/static',
to: publicDirectory,
},
]),
new WebpackManifestPlugin({
fileName: '../manifest.json',
filter(options) {
if (options.name === 'script.js') return true;
if (options.name === 'style.css') return true;
return false;
},
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment