webpack.config.js
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
webpack.config.js
use: [
'style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
additionalData: `
@import "src/scss-vars.scss";
`,
sassOptions: {
includePaths: [__dirname]
},
},
},
],
src/scss-vars.scss
$color: orange;
src/scss-export.scss
:export {
color: $color;
}
webpack.config.js
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
compileType: 'icss',
},
},
},
{
loader: 'sass-loader',
options: {
additionalData: `
@import "src/scss-vars.scss";
`,
sassOptions: {
includePaths: [__dirname]
},
},
},
],
webpack.config.js
const ESLintPlugin = require('eslint-webpack-plugin')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const mode = 'production'
const cssLoaders = (...loaders) => [
mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: {
compileType: 'icss',
},
},
},
...loaders
]
module.exports = {
mode,
plugins: [new ESLintPlugin({
extensions: ['.js', '.jsx', '.ts', '.tsx'] // 不加 .jsx 就不会检查 jsx 文件了
}), new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
})],
output: {
filename: '[name].[contenthash].js'
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src/')
}
},
...
webpack.config.js
const ESLintPlugin = require('eslint-webpack-plugin')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const mode = 'production'
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cssLoaders = (...loaders) => [
mode === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: {
modules: {
compileType: 'icss',
},
},
},
...loaders
]
module.exports = {
mode,
plugins: [
new ESLintPlugin({
extensions: ['.js', '.jsx', '.ts', '.tsx'] // 不加 .jsx 就不会检查 jsx 文件了
}),
mode === 'production' && new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
new HtmlWebpackPlugin()
].filter(Boolean),
output: {
filename: '[name].[contenthash].js'
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src/')
}
},
...