How to setup webpack plugins with hot reload with Next.js?
up vote
0
down vote
favorite
I'm using a project based on the example at https://github.com/zeit/next.js/tree/master/examples/custom-server-typescript
I've configured a Babel plugin in next.config.js
as follows:
let config = withTypescript({
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: "secret"
},
publicRuntimeConfig: {
// Will be available on both server and client
port: parseInt(process.env.PORT, 10) || 3000,
mySecret: process.env.MY_SECRET // Pass through env variables
},
// See https://github.com/zeit/next.js/tree/master/examples/with-sw-precache
webpack: config => {
config.plugins.push(
new SWPrecacheWebpackPlugin({
verbose: true,
staticFileGlobsIgnorePatterns: [/.next//],
runtimeCaching: [
{
handler: "networkFirst",
urlPattern: /^https?.*/
}
]
})
)
return config
}
})
module.exports = config
When I run the yarn build
(whose script is next build && tsc --project tsconfig.server.json
) the webpack plugin is run and the service-worker.js
is generated as expected.
However, when I run yarn dev
(whose script is nodemon server/index.ts
), the Webpack plugin isn't run and no service-worker.js
is generated.
So as best I can tell Webpack is not run directly when I use yarn dev
and it only uses ts-node
on the TypeScript source. If my understanding on this is correct, how can I get hot-reloading AND load other babel plugins (as configured in next.config.js
)? If my understanding is off, please enlighten me!
typescript webpack next.js
add a comment |
up vote
0
down vote
favorite
I'm using a project based on the example at https://github.com/zeit/next.js/tree/master/examples/custom-server-typescript
I've configured a Babel plugin in next.config.js
as follows:
let config = withTypescript({
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: "secret"
},
publicRuntimeConfig: {
// Will be available on both server and client
port: parseInt(process.env.PORT, 10) || 3000,
mySecret: process.env.MY_SECRET // Pass through env variables
},
// See https://github.com/zeit/next.js/tree/master/examples/with-sw-precache
webpack: config => {
config.plugins.push(
new SWPrecacheWebpackPlugin({
verbose: true,
staticFileGlobsIgnorePatterns: [/.next//],
runtimeCaching: [
{
handler: "networkFirst",
urlPattern: /^https?.*/
}
]
})
)
return config
}
})
module.exports = config
When I run the yarn build
(whose script is next build && tsc --project tsconfig.server.json
) the webpack plugin is run and the service-worker.js
is generated as expected.
However, when I run yarn dev
(whose script is nodemon server/index.ts
), the Webpack plugin isn't run and no service-worker.js
is generated.
So as best I can tell Webpack is not run directly when I use yarn dev
and it only uses ts-node
on the TypeScript source. If my understanding on this is correct, how can I get hot-reloading AND load other babel plugins (as configured in next.config.js
)? If my understanding is off, please enlighten me!
typescript webpack next.js
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using a project based on the example at https://github.com/zeit/next.js/tree/master/examples/custom-server-typescript
I've configured a Babel plugin in next.config.js
as follows:
let config = withTypescript({
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: "secret"
},
publicRuntimeConfig: {
// Will be available on both server and client
port: parseInt(process.env.PORT, 10) || 3000,
mySecret: process.env.MY_SECRET // Pass through env variables
},
// See https://github.com/zeit/next.js/tree/master/examples/with-sw-precache
webpack: config => {
config.plugins.push(
new SWPrecacheWebpackPlugin({
verbose: true,
staticFileGlobsIgnorePatterns: [/.next//],
runtimeCaching: [
{
handler: "networkFirst",
urlPattern: /^https?.*/
}
]
})
)
return config
}
})
module.exports = config
When I run the yarn build
(whose script is next build && tsc --project tsconfig.server.json
) the webpack plugin is run and the service-worker.js
is generated as expected.
However, when I run yarn dev
(whose script is nodemon server/index.ts
), the Webpack plugin isn't run and no service-worker.js
is generated.
So as best I can tell Webpack is not run directly when I use yarn dev
and it only uses ts-node
on the TypeScript source. If my understanding on this is correct, how can I get hot-reloading AND load other babel plugins (as configured in next.config.js
)? If my understanding is off, please enlighten me!
typescript webpack next.js
I'm using a project based on the example at https://github.com/zeit/next.js/tree/master/examples/custom-server-typescript
I've configured a Babel plugin in next.config.js
as follows:
let config = withTypescript({
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: "secret"
},
publicRuntimeConfig: {
// Will be available on both server and client
port: parseInt(process.env.PORT, 10) || 3000,
mySecret: process.env.MY_SECRET // Pass through env variables
},
// See https://github.com/zeit/next.js/tree/master/examples/with-sw-precache
webpack: config => {
config.plugins.push(
new SWPrecacheWebpackPlugin({
verbose: true,
staticFileGlobsIgnorePatterns: [/.next//],
runtimeCaching: [
{
handler: "networkFirst",
urlPattern: /^https?.*/
}
]
})
)
return config
}
})
module.exports = config
When I run the yarn build
(whose script is next build && tsc --project tsconfig.server.json
) the webpack plugin is run and the service-worker.js
is generated as expected.
However, when I run yarn dev
(whose script is nodemon server/index.ts
), the Webpack plugin isn't run and no service-worker.js
is generated.
So as best I can tell Webpack is not run directly when I use yarn dev
and it only uses ts-node
on the TypeScript source. If my understanding on this is correct, how can I get hot-reloading AND load other babel plugins (as configured in next.config.js
)? If my understanding is off, please enlighten me!
typescript webpack next.js
typescript webpack next.js
edited Nov 6 at 2:49
asked Nov 5 at 1:50
Scott Willeke
6,34912642
6,34912642
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147325%2fhow-to-setup-webpack-plugins-with-hot-reload-with-next-js%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password