|
1 |
| -const HtmlWebpackPlugin = require('html-webpack-plugin') |
2 |
| -const { CleanWebpackPlugin } = require('clean-webpack-plugin') |
3 |
| -const CopyWebpackPlugin = require('copy-webpack-plugin') |
4 |
| -const path = require('path') |
5 |
| - |
6 |
| -const targetFolderName = 'dist' |
7 |
| -const outputPath = path.resolve(__dirname, targetFolderName) |
8 |
| -const packageJSON = require('./package.json') |
9 |
| - |
10 |
| - |
11 |
| -module.exports = { |
12 |
| - mode: 'development', |
13 |
| - entry: { |
14 |
| - app: packageJSON.main |
15 |
| - }, |
16 |
| - node: { |
17 |
| - buffer: false, |
18 |
| - setImmediate: false |
19 |
| - }, |
20 |
| - devServer: { |
21 |
| - contentBase: outputPath, |
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 |
| - } |
34 |
| - }, |
35 |
| - resolve: { |
36 |
| - modules: [ |
37 |
| - path.resolve('./src'), |
38 |
| - path.resolve('./node_modules') |
39 |
| - ], |
40 |
| - extensions: ['.js'] |
41 |
| - }, |
42 |
| - output: { |
43 |
| - filename: 'js/[name].[contenthash].bundle.js', |
44 |
| - chunkFilename: 'js/[name].[contenthash].bundle.js', |
45 |
| - path: outputPath |
46 |
| - }, |
47 |
| - optimization: { |
48 |
| - splitChunks: { |
49 |
| - chunks: 'all', |
50 |
| - cacheGroups: { |
51 |
| - // make separate 'vendor' chunk that contains any depenedencies |
52 |
| - // allows for smaller file sizes and faster builds |
53 |
| - vendor: { |
54 |
| - test: /node_modules/, |
55 |
| - chunks: 'initial', |
56 |
| - name: 'vendor', |
57 |
| - priority: 10, |
58 |
| - enforce: true |
59 |
| - } |
60 |
| - } |
61 |
| - }, |
62 |
| - runtimeChunk: 'single' |
63 |
| - }, |
64 |
| - plugins: [ |
65 |
| - new CleanWebpackPlugin(), |
66 |
| - new HtmlWebpackPlugin({ |
67 |
| - title: "app", |
68 |
| - filename: path.resolve(__dirname, 'dist', 'index.html') |
69 |
| - }), |
70 |
| - new CopyWebpackPlugin({ |
71 |
| - patterns: [ |
72 |
| - { from: './assets/**/*', to: './examples/assets', flatten: true, noErrorOnMissing: true }, |
73 |
| - { from: './node_modules/@arction/lcjs/dist/resources', to: 'resources', noErrorOnMissing: true }, |
74 |
| - ] |
75 |
| - }) |
76 |
| - ] |
77 |
| -} |
| 1 | +const HtmlWebpackPlugin = require('html-webpack-plugin') |
| 2 | +const { CleanWebpackPlugin } = require('clean-webpack-plugin') |
| 3 | +const CopyWebpackPlugin = require('copy-webpack-plugin') |
| 4 | +const path = require('path') |
| 5 | + |
| 6 | +const targetFolderName = 'dist' |
| 7 | +const outputPath = path.resolve(__dirname, targetFolderName) |
| 8 | +const packageJSON = require('./package.json') |
| 9 | + |
| 10 | + |
| 11 | +module.exports = { |
| 12 | + mode: 'development', |
| 13 | + entry: { |
| 14 | + app: packageJSON.main |
| 15 | + }, |
| 16 | + node: { |
| 17 | + buffer: false, |
| 18 | + setImmediate: false |
| 19 | + }, |
| 20 | + devServer: { |
| 21 | + contentBase: outputPath, |
| 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 | + } |
| 34 | + }, |
| 35 | + resolve: { |
| 36 | + modules: [ |
| 37 | + path.resolve('./src'), |
| 38 | + path.resolve('./node_modules') |
| 39 | + ], |
| 40 | + extensions: ['.js'] |
| 41 | + }, |
| 42 | + output: { |
| 43 | + filename: 'js/[name].[contenthash].bundle.js', |
| 44 | + chunkFilename: 'js/[name].[contenthash].bundle.js', |
| 45 | + path: outputPath |
| 46 | + }, |
| 47 | + optimization: { |
| 48 | + splitChunks: { |
| 49 | + chunks: 'all', |
| 50 | + cacheGroups: { |
| 51 | + // make separate 'vendor' chunk that contains any depenedencies |
| 52 | + // allows for smaller file sizes and faster builds |
| 53 | + vendor: { |
| 54 | + test: /node_modules/, |
| 55 | + chunks: 'initial', |
| 56 | + name: 'vendor', |
| 57 | + priority: 10, |
| 58 | + enforce: true |
| 59 | + } |
| 60 | + } |
| 61 | + }, |
| 62 | + runtimeChunk: 'single' |
| 63 | + }, |
| 64 | + plugins: [ |
| 65 | + new CleanWebpackPlugin(), |
| 66 | + new HtmlWebpackPlugin({ |
| 67 | + title: "app", |
| 68 | + filename: path.resolve(__dirname, 'dist', 'index.html') |
| 69 | + }), |
| 70 | + new CopyWebpackPlugin({ |
| 71 | + patterns: [ |
| 72 | + { from: './assets/**/*', to: './examples/assets', flatten: true, noErrorOnMissing: true }, |
| 73 | + { from: './node_modules/@arction/lcjs/dist/resources', to: 'resources', noErrorOnMissing: true }, |
| 74 | + ] |
| 75 | + }) |
| 76 | + ] |
| 77 | +} |
0 commit comments