-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
192 additions
and
118 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
const {SRC_PATH, PROJECT_PATH} = require('./0.app-path'); | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | ||
|
||
const isProduction = process.env.NODE_ENV === 'production'; | ||
/** | ||
* 各种loader文件的默认配置,需要在设置环境变量的方法set_NODE_ENV之后再引入。 | ||
* **/ | ||
const fontLoader = { | ||
test: /\.(eot|woff2?|ttf)$/, | ||
use: [ | ||
{ | ||
loader: "url-loader", | ||
options: { | ||
name: process.env.NODE_ENV === 'production' ? 'fonts/[name].[hash].[ext]' : '[path][name].[ext]', | ||
limit: 5120, | ||
publicPath: "/", | ||
context: SRC_PATH, | ||
outputPath: "/" | ||
} | ||
} | ||
] | ||
}; | ||
const imgLoader = { | ||
test: /\.(png|jpe?g|gif|svg)$/, | ||
use: [ | ||
{ | ||
loader: 'url-loader', | ||
options: { | ||
limit: 10240, | ||
name: process.env.NODE_ENV === 'production' ? 'images/[hash].[ext]' : '[path][name].[ext]', | ||
publicPath: '/', | ||
context: SRC_PATH, //源码目录,这里更改context,是为了在开发环境下,导出图片和图片源的路径一致 | ||
outputPath: '/' | ||
} | ||
} | ||
] | ||
}; | ||
const languageLoader = { | ||
ts: { | ||
test: /\.tsx?$/, | ||
use: [ | ||
'babel-loader', | ||
'ts-loader' | ||
] | ||
}, | ||
js: { | ||
test: /\.js$/, | ||
use: [ | ||
'babel-loader' | ||
] | ||
} | ||
}; | ||
const styleLoader = { | ||
sass: { | ||
test: /\.(scss|sass)$/, | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
"css-loader", // translates CSS into CommonJS | ||
"sass-loader" // compiles Sass to CSS, using Node Sass by default | ||
] | ||
}, | ||
less: { | ||
test: /\.less$/, | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
"css-loader", // translates CSS into CommonJS | ||
"less-loader" // compiles Less to CSS | ||
] | ||
}, | ||
css: { | ||
test: /\.css$/, | ||
use: [ | ||
MiniCssExtractPlugin.loader, | ||
"css-loader", // translates CSS into CommonJS | ||
] | ||
} | ||
}; | ||
|
||
|
||
|
||
const htmlLoaderConfig = { | ||
minimize: isProduction, | ||
removeComments: isProduction, | ||
collapseWhitespace: isProduction, | ||
attrs: [':src', ':href'] | ||
}; | ||
const templateConfig = { | ||
html: { | ||
test: /\.html$/, | ||
use: [ | ||
{ | ||
loader: 'html-loader', | ||
options: htmlLoaderConfig | ||
} | ||
] | ||
}, | ||
ejs: { | ||
test: /\.ejs$/, | ||
use: [ | ||
{ | ||
loader: 'html-loader', | ||
options: htmlLoaderConfig | ||
}, | ||
{ | ||
loader: path.resolve(__dirname, '../loaders/ejs-loader.js'), //自己简单实现的使用ejs2 engine的ejs-loader | ||
options: { | ||
context: PROJECT_PATH | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
|
||
module.exports = { | ||
fontLoader, | ||
imgLoader, | ||
languageLoader, | ||
styleLoader, | ||
templateConfig | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,9 @@ | ||
const {SRC_PATH} = require('./0.app-path'); | ||
let {fontLoader} = require('./0.loader-config'); | ||
/** | ||
* 添加字体文件配置 | ||
* **/ | ||
function addFontConfig(config) { | ||
config.module.rules.push({ | ||
test: /\.(eot|woff2?|ttf)$/, | ||
use: [ | ||
{ | ||
loader: "url-loader", | ||
options: { | ||
name: process.env.NODE_ENV === 'production' ? 'fonts/[name].[hash].[ext]' : '[path][name].[ext]', | ||
limit: 5120, | ||
publicPath: "/", | ||
context: SRC_PATH, | ||
outputPath: "/" | ||
} | ||
} | ||
] | ||
}); | ||
config.module.rules.push(fontLoader); | ||
return config; | ||
} | ||
module.exports = addFontConfig; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
const appConfig = require('../../app.config'); | ||
const {languageLoader} = require('./0.loader-config'); | ||
let {getType} = require('./utils'); | ||
|
||
|
||
/** | ||
* 对代码配置babel | ||
* **/ | ||
module.exports = function (config) { | ||
|
||
|
||
let language = appConfig.language || 'js'; | ||
let resolve; | ||
if(getType(language) === 'string'){ | ||
resolve = [language]; | ||
} | ||
else if(getType(language) === 'array'){ | ||
resolve = language; | ||
} | ||
else { | ||
throw new Error(`app.config language 配置错误`); | ||
} | ||
config.resolve.extensions = resolve; | ||
|
||
resolve.forEach(v => { | ||
if(!languageLoader[v]){ | ||
throw new Error(`未找到${v}文件对应的loader默认配置`); | ||
} | ||
config.module.rules.push(languageLoader[v]); | ||
}); | ||
|
||
return config; | ||
}; |
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
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
Oops, something went wrong.