Skip to content

Commit

Permalink
custom webpack loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mogu authored and mogu committed Jul 29, 2020
1 parent 11562a2 commit b9a6308
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 23 deletions.
223 changes: 205 additions & 18 deletions webpack/first/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion webpack/first/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config build/webpack.config.js"
"build": "webpack --config build/webpack.config.js",
"dev": "npx wabpack --config webpack.config.js"
},
"keywords": [],
"author": "",
Expand All @@ -22,5 +23,8 @@
"style-loader": "^1.1.2",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
},
"dependencies": {
"loader-utils": "^2.0.0"
}
}
9 changes: 9 additions & 0 deletions webpack/first/repalce-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const loaderUtils = require('loader-utils')

module.exports = function(source) {
const options = loaderUtils.getOptions(this)
console.log('options', options)
const result = source.replace('call', options.name)
console.log('source', result)
return result
}
4 changes: 2 additions & 2 deletions webpack/first/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './assets/index.css'
import './assets/index.less'
// import './assets/index.css'
// import './assets/index.less'

console.log('call mobar')
25 changes: 25 additions & 0 deletions webpack/first/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('path')

module.exports = {
mode: 'development',
entry: {
main: './src/main.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: path.resolve(__dirname, './repalce-loader.js'),
options: {
name: 'cccc'
}
}
}
]
}
}
4 changes: 2 additions & 2 deletions 数据结构和算法/linklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function reverseList(list) {
let arr = []
let head = list
let temp = head
console.log(temp)
// console.log(temp)
while(temp) {
arr.push(temp.value)
temp = temp.next
}
console.log(arr)
// console.log(arr)
temp = head

while(temp) {
Expand Down

0 comments on commit b9a6308

Please sign in to comment.