-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.common.js
executable file
·137 lines (136 loc) · 3.43 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const autoprefixer = require('autoprefixer');
const sass = require('sass');
module.exports = {
cache: true,
target: ['web', 'es5'],
entry: {
// bundle: `${__dirname}/src/js/index.js`,
bundle: `${__dirname}/src/scss/site.scss`,
},
output: {
path: `${__dirname}/dest/`,
publicPath: 'auto',
filename: '[name].js',
chunkFilename: `[name].chunk.js?date=${new Date().getTime()}`,
assetModuleFilename: 'assets/[name][ext]',
},
optimization: {
splitChunks: {
name: 'vendor',
chunks: 'initial',
},
},
resolve: {
extensions: ['.vue', '.js', '.ts', '.tsx'],
alias: {
'@': path.resolve(__dirname, './src/js'),
vue$: 'vue/dist/vue.runtime.esm-bundler.js',
},
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
include: /src\/js/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.vue$/,
include: /src\/js/,
loader: 'vue-loader',
options: {
loaders: {
scss: 'vue-style-loader!css-loader!sass-loader', // <style lang="scss">
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax', // <style lang="sass">
},
},
},
{
test: /\.(scss|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: true,
// 0 => no loaders (default);
// 1 => postcss-loader;
// 2 => postcss-loader, sass-loader
importLoaders: 2,
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
autoprefixer({
grid: 'no-autoplace',
}),
],
},
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
implementation: sass,
sourceMap: true,
sassOptions: {
outputStyle: 'expanded',
},
},
},
],
},
{
test: /\.(jpg|png|svg|woff|woff2|eot|ttf)(\?.*$|$)/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 4 * 1024, // <--- 4kb
},
},
},
],
},
plugins: [
// ESLint
new ESLintPlugin({
context: './src',
extensions: ['js', 'ts', 'tsx', 'jsx', 'vue'],
exclude: ['/node_modules/'],
emitError: true,
emitWarning: true,
failOnError: true,
fix: true,
}),
// StyleLint
new StylelintPlugin({
configFile: '.stylelintrc',
context: './src/scss',
emitError: true,
emitWarning: true,
failOnError: true,
fix: true,
}),
// cssの書き出し
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: `[name].chunk.css?date=${new Date().getTime()}`,
}),
// 余分なJSを書き出さない
new RemoveEmptyScriptsPlugin(),
],
};