Skip to content

Commit cb69973

Browse files
committed
Add support for loading assets from assets folder
1 parent 63d4c5d commit cb69973

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"private": true,
99
"main": "./src/index.js",
1010
"devDependencies": {
11+
"copy-webpack-plugin": "^6.0.2",
1112
"html-webpack-plugin": "^3.2.0",
1213
"webpack-cli": "^3.3.10",
1314
"webpack-dev-server": "^3.9.0"

webpack.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const HtmlWebpackPlugin = require('html-webpack-plugin')
22
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
3+
const CopyWebpackPlugin = require('copy-webpack-plugin')
34
const path = require('path')
45

56
const targetFolderName = 'dist'
@@ -18,7 +19,18 @@ module.exports = {
1819
},
1920
devServer: {
2021
contentBase: outputPath,
21-
compress: true
22+
compress: true,
23+
// handle asset renaming
24+
before: function(app, server, compiler){
25+
app.get('/examples/assets/*', (req, res, next)=>{
26+
if(req.originalUrl.match(/lcjs_example_\d*_\w*-/g)){
27+
res.redirect(req.originalUrl.replace(/lcjs_example_\d*_\w*-/g,''))
28+
}
29+
else{
30+
next()
31+
}
32+
})
33+
}
2234
},
2335
resolve: {
2436
modules: [
@@ -54,6 +66,11 @@ module.exports = {
5466
new HtmlWebpackPlugin({
5567
title: "app",
5668
filename: path.resolve(__dirname, 'dist', 'index.html')
69+
}),
70+
new CopyWebpackPlugin({
71+
patterns: [
72+
{ from: './assets/**/*', to: './examples/assets', flatten: true, noErrorOnMissing: true }
73+
]
5774
})
5875
]
5976
}

0 commit comments

Comments
 (0)