Skip to content

Commit 446a68a

Browse files
committed
chore: recover webpack plugin setup
1 parent 475cd8a commit 446a68a

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

webpack/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
// @if jasmine || mocha
3030
"webpack-shell-plugin-next": "^2.3.1",
3131
// @endif
32+
// @if plugin
33+
"webpack-node-externals": "^3.0.0",
34+
// @endif
3235
},
3336
"scripts": {
3437
"start": "webpack serve",

webpack/webpack.config.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const TerserPlugin = require('terser-webpack-plugin');
99
// @if jasmine || mocha
1010
const WebpackShellPluginNext = require('webpack-shell-plugin-next')
1111
// @endif
12+
// @if plugin
13+
const nodeExternals = require('webpack-node-externals');
14+
// @endif
1215

1316
// @if sass
1417
const sassLoader = {
@@ -36,7 +39,12 @@ module.exports = function(env, { /* @if jasmine || mocha*/runTest, /* @endif */a
3639
const test = env.test || process.env.NODE_ENV === 'test';
3740
// @endif
3841
return {
42+
// @if app
3943
target: 'web',
44+
// @endif
45+
// @if plugin
46+
target: production ? 'node' : 'web',
47+
// @endif
4048
mode: production ? 'production' : 'development',
4149
devtool: production ? undefined : 'eval-source-map',
4250
optimization: {
@@ -56,22 +64,42 @@ module.exports = function(env, { /* @if jasmine || mocha*/runTest, /* @endif */a
5664
entry: {
5765
entry: test ?
5866
'./test/all-spec./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */' :
67+
// @if app
5968
'./src/main./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */'
69+
// @endif
70+
// @if plugin
71+
// Build only plugin in production mode,
72+
// build dev-app in non-production mode
73+
(production ? './src/index./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */' : './dev-app/main./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */')
74+
// @endif
6075
},
6176
// @endif
6277
// @if !jasmine && !mocha
6378
entry: {
79+
// @if app
6480
entry: './src/main./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */'
81+
// @endif
82+
// @if plugin
83+
// Build only plugin in production mode,
84+
// build dev-app in non-production mode
85+
entry: production? './src/index./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */' : './dev-app/main./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */'
86+
// @endif
6587
},
6688
// @endif
6789
output: {
6890
clean: true,
6991
path: path.resolve(__dirname, 'dist'),
92+
// @if app
7093
filename: production ? '[name].[contenthash].bundle.js' : '[name].bundle.js'
94+
// @endif
95+
// @if plugin
96+
filename: production ? 'index.js' : '[name].bundle.js',
97+
library: production ? { type: 'commonjs' } : undefined
98+
// @endif
7199
},
72100
resolve: {
73101
extensions: [/* @if typescript */'.ts', /* @endif */'.js'],
74-
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
102+
modules: [path.resolve(__dirname, 'src'),/* @if plugin */ path.resolve(__dirname, 'dev-app'),/* @endif */ 'node_modules'],
75103
alias: production ? {
76104
// add your production aliases here
77105
} : {
@@ -178,7 +206,12 @@ module.exports = function(env, { /* @if jasmine || mocha*/runTest, /* @endif */a
178206
{ test: /\.ts$/i, use: ['ts-loader', '@aurelia/webpack-loader'], exclude: /node_modules/ },
179207
// @endif
180208
{
209+
// @if app
181210
test: /[/\\]src[/\\].+\.html$/i,
211+
// @endif
212+
// @if plugin
213+
test: /[/\\](?:src|dev-app)[/\\].+\.html$/i,
214+
// @endif
182215
// @if shadow-dom
183216
use: {
184217
loader: '@aurelia/webpack-loader',
@@ -198,8 +231,15 @@ module.exports = function(env, { /* @if jasmine || mocha*/runTest, /* @endif */a
198231
}
199232
]
200233
},
234+
// @if plugin
235+
externalsPresets: { node: production },
236+
externals: [
237+
// Skip npm dependencies in plugin build.
238+
production && nodeExternals()
239+
].filter(p => p),
240+
// @endif
201241
plugins: [
202-
new HtmlWebpackPlugin({ template: 'index.html', favicon: 'favicon.ico' }),
242+
/* @if plugin */!production && /* @endif */new HtmlWebpackPlugin({ template: 'index.html', favicon: 'favicon.ico' }),
203243
new Dotenv({
204244
path: `./.env${production ? '' : '.' + (process.env.NODE_ENV || 'development')}`,
205245
}),

0 commit comments

Comments
 (0)